diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 88cd9c120..efddea49b 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -28,6 +28,7 @@ * [#3872](https://github.com/netbox-community/netbox/issues/3872) - Paginate related IPs of an address * [#3876](https://github.com/netbox-community/netbox/issues/3876) - Fixed min/max to ASN input field at the site creation page * [#3882](https://github.com/netbox-community/netbox/issues/3882) - Fix filtering of devices by rack group +* [#3900](https://github.com/netbox-community/netbox/issues/3882) - Fix exception when deleting a device type with templated components --- diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 69c3c3475..42b533171 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 device type + try: + parent = getattr(self, 'device_type', None) + except ObjectDoesNotExist: + # The parent device type 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) )