Fixes #3900: component template related object existance not checked

This commit is contained in:
Saria Hajjar 2020-01-13 09:31:06 +00:00
parent b7e78028ce
commit 4e2046138c
2 changed files with 9 additions and 1 deletions

View File

@ -28,6 +28,7 @@
* [#3872](https://github.com/netbox-community/netbox/issues/3872) - Paginate related IPs of an address * [#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 * [#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 * [#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
--- ---

View File

@ -38,11 +38,18 @@ class ComponentTemplateModel(models.Model):
raise NotImplementedError() raise NotImplementedError()
def to_objectchange(self, action): 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( return ObjectChange(
changed_object=self, changed_object=self,
object_repr=str(self), object_repr=str(self),
action=action, action=action,
related_object=self.device_type, related_object=parent,
object_data=serialize_object(self) object_data=serialize_object(self)
) )