From 4e2046138c70b62f0376132ca96038cac57646ec Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Mon, 13 Jan 2020 09:31:06 +0000 Subject: [PATCH] Fixes #3900: component template related object existance not checked --- docs/release-notes/version-2.6.md | 1 + netbox/dcim/models.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) 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) )