From 01fa2710eba125dbc49e5378198fc10f178e58bd Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 13 Feb 2024 10:20:26 -0500 Subject: [PATCH] Fixes #15067: Fix uncaught exception when attempting invalid device bay import --- netbox/dcim/forms/bulk_import.py | 2 +- netbox/dcim/models/device_components.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/netbox/dcim/forms/bulk_import.py b/netbox/dcim/forms/bulk_import.py index f30ff91fa..732bb87ae 100644 --- a/netbox/dcim/forms/bulk_import.py +++ b/netbox/dcim/forms/bulk_import.py @@ -996,7 +996,7 @@ class DeviceBayImportForm(NetBoxModelImportForm): device_type__subdevice_role=SubdeviceRoleChoices.ROLE_CHILD ).exclude(pk=device.pk) else: - self.fields['installed_device'].queryset = Interface.objects.none() + self.fields['installed_device'].queryset = Device.objects.none() class InventoryItemImportForm(NetBoxModelImportForm): diff --git a/netbox/dcim/models/device_components.py b/netbox/dcim/models/device_components.py index 88dddb312..5b2564b32 100644 --- a/netbox/dcim/models/device_components.py +++ b/netbox/dcim/models/device_components.py @@ -1133,13 +1133,13 @@ class DeviceBay(ComponentModel, TrackingModelMixin): super().clean() # 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( device_type=self.device.device_type )) # 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.")) # Check that the installed device is not already installed elsewhere