Przeglądaj źródła

Fixes #3900: Fix exception when deleting device types

Jeremy Stretch 6 lat temu
rodzic
commit
1ea820a50e
2 zmienionych plików z 9 dodań i 1 usunięć
  1. 1 0
      docs/release-notes/version-2.6.md
  2. 8 1
      netbox/dcim/models.py

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

@@ -6,6 +6,7 @@
 
 ## Bug Fixes
 
+* [#3900](https://github.com/netbox-community/netbox/issues/3900) - Fix exception when deleting device types
 * [#3914](https://github.com/netbox-community/netbox/issues/3914) - Fix interface filter field when unauthenticated
 
 ---

+ 8 - 1
netbox/dcim/models.py

@@ -38,11 +38,18 @@ class ComponentTemplateModel(models.Model):
         raise NotImplementedError()
 
     def to_objectchange(self, action):
+        # Annotate the parent DeviceType
+        try:
+            parent = getattr(self, 'device_type', None)
+        except ObjectDoesNotExist:
+            # The parent DeviceType has already been deleted
+            parent = None
+
         return ObjectChange(
             changed_object=self,
             object_repr=str(self),
             action=action,
-            related_object=self.device_type,
+            related_object=parent,
             object_data=serialize_object(self)
         )