Pārlūkot izejas kodu

Fixes #3596: Prevent server error when reassigning a device to a new device bay

Jeremy Stretch 6 gadi atpakaļ
vecāks
revīzija
7467347af1
2 mainītis faili ar 13 papildinājumiem un 1 dzēšanām
  1. 3 1
      docs/release-notes/version-2.6.md
  2. 10 0
      netbox/dcim/models.py

+ 3 - 1
docs/release-notes/version-2.6.md

@@ -2,12 +2,14 @@
 
 ## Enhancements
 
-* [#3340](https://github.com/netbox-community/netbox/issues/3340) - Add missing options to connect front ports to console ports
 * [#3445](https://github.com/netbox-community/netbox/issues/3445) - Add support for additional user defined headers to be added to webhook requests
 * [#3499](https://github.com/netbox-community/netbox/issues/3499) - Add `ca_file_path` to Webhook model to support user supplied CA certificate verification of webhook requests
 
 ## Bug Fixes
 
+* [#3340](https://github.com/netbox-community/netbox/issues/3340) - Add missing options to connect front ports to console ports
+* [#3596](https://github.com/netbox-community/netbox/issues/3596) - Prevent server error when reassigning a device to a new device bay
+
 ---
 
 # v2.6.6 (2019-10-10)

+ 10 - 0
netbox/dcim/models.py

@@ -2588,6 +2588,16 @@ class DeviceBay(ComponentModel):
         if self.device == self.installed_device:
             raise ValidationError("Cannot install a device into itself.")
 
+        # Check that the installed device is not already installed elsewhere
+        if self.installed_device:
+            current_bay = DeviceBay.objects.filter(installed_device=self.installed_device).first()
+            if current_bay:
+                raise ValidationError({
+                    'installed_device': "Cannot install the specified device; device is already installed in {}".format(
+                        current_bay
+                    )
+                })
+
 
 #
 # Inventory items