From 2269bf01672119d22587aaec9477b2547cb69bfe Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 8 Apr 2022 09:08:55 -0400 Subject: [PATCH] Fixes #9079: Fail validation when an inventory item is assigned as its own parent --- docs/release-notes/version-3.2.md | 1 + netbox/dcim/models/device_components.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/docs/release-notes/version-3.2.md b/docs/release-notes/version-3.2.md index 1d2516cdf..ea5a2374a 100644 --- a/docs/release-notes/version-3.2.md +++ b/docs/release-notes/version-3.2.md @@ -12,6 +12,7 @@ * [#9057](https://github.com/netbox-community/netbox/issues/9057) - Fix missing instance counts for module types * [#9061](https://github.com/netbox-community/netbox/issues/9061) - Change inheritance order for DeviceComponentFilterSets * [#9065](https://github.com/netbox-community/netbox/issues/9065) - Min/max VID should not be required when filtering VLAN groups +* [#9079](https://github.com/netbox-community/netbox/issues/9079) - Fail validation when an inventory item is assigned as its own parent --- diff --git a/netbox/dcim/models/device_components.py b/netbox/dcim/models/device_components.py index ab5d24867..3ed786000 100644 --- a/netbox/dcim/models/device_components.py +++ b/netbox/dcim/models/device_components.py @@ -1070,3 +1070,12 @@ class InventoryItem(MPTTModel, ComponentModel): def get_absolute_url(self): return reverse('dcim:inventoryitem', kwargs={'pk': self.pk}) + + def clean(self): + super().clean() + + # An InventoryItem cannot be its own parent + if self.pk and self.parent_id == self.pk: + raise ValidationError({ + "parent": "Cannot assign self as parent." + })