Procházet zdrojové kódy

Fixes #15067: Fix uncaught exception when attempting invalid device bay import

Jeremy Stretch před 2 roky
rodič
revize
01fa2710eb

+ 1 - 1
netbox/dcim/forms/bulk_import.py

@@ -996,7 +996,7 @@ class DeviceBayImportForm(NetBoxModelImportForm):
                 device_type__subdevice_role=SubdeviceRoleChoices.ROLE_CHILD
                 device_type__subdevice_role=SubdeviceRoleChoices.ROLE_CHILD
             ).exclude(pk=device.pk)
             ).exclude(pk=device.pk)
         else:
         else:
-            self.fields['installed_device'].queryset = Interface.objects.none()
+            self.fields['installed_device'].queryset = Device.objects.none()
 
 
 
 
 class InventoryItemImportForm(NetBoxModelImportForm):
 class InventoryItemImportForm(NetBoxModelImportForm):

+ 2 - 2
netbox/dcim/models/device_components.py

@@ -1133,13 +1133,13 @@ class DeviceBay(ComponentModel, TrackingModelMixin):
         super().clean()
         super().clean()
 
 
         # Validate that the parent Device can have DeviceBays
         # Validate that the parent Device can have DeviceBays
-        if not self.device.device_type.is_parent_device:
+        if hasattr(self, 'device') and not self.device.device_type.is_parent_device:
             raise ValidationError(_("This type of device ({device_type}) does not support device bays.").format(
             raise ValidationError(_("This type of device ({device_type}) does not support device bays.").format(
                 device_type=self.device.device_type
                 device_type=self.device.device_type
             ))
             ))
 
 
         # Cannot install a device into itself, obviously
         # Cannot install a device into itself, obviously
-        if self.device == self.installed_device:
+        if self.installed_device and getattr(self, 'device', None) == self.installed_device:
             raise ValidationError(_("Cannot install a device into itself."))
             raise ValidationError(_("Cannot install a device into itself."))
 
 
         # Check that the installed device is not already installed elsewhere
         # Check that the installed device is not already installed elsewhere