Skip to content

Commit 1ea820a

Browse files
committed
Fixes #3900: Fix exception when deleting device types
1 parent 685cf50 commit 1ea820a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

docs/release-notes/version-2.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
## Bug Fixes
88

9+
* [#3900](https://github.com/netbox-community/netbox/issues/3900) - Fix exception when deleting device types
910
* [#3914](https://github.com/netbox-community/netbox/issues/3914) - Fix interface filter field when unauthenticated
1011

1112
---

netbox/dcim/models.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,18 @@ def instantiate(self, device):
3838
raise NotImplementedError()
3939

4040
def to_objectchange(self, action):
41+
# Annotate the parent DeviceType
42+
try:
43+
parent = getattr(self, 'device_type', None)
44+
except ObjectDoesNotExist:
45+
# The parent DeviceType has already been deleted
46+
parent = None
47+
4148
return ObjectChange(
4249
changed_object=self,
4350
object_repr=str(self),
4451
action=action,
45-
related_object=self.device_type,
52+
related_object=parent,
4653
object_data=serialize_object(self)
4754
)
4855

0 commit comments

Comments
 (0)