diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 792e8990a..e3ad87ad0 100644 --- a/docs/release-notes/version-2.6.md +++ b/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 --- diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 833fb483b..8ab3a37a3 100644 --- a/netbox/dcim/models.py +++ b/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) )