From 75106e1cca7cec17b794b1f984dc5866a6eb0bc6 Mon Sep 17 00:00:00 2001 From: Martin Hauser Date: Mon, 2 Feb 2026 21:06:19 +0100 Subject: [PATCH] fix(dcim): Validate location/site relationship using FK IDs Use `site_id` and `location_id` for validation to avoid triggering related object lookups during import/validation. This aligns the logic with the underlying foreign key fields and prevents `RelatedObjectDoesNotExist` errors when relations are unset. Fixes: #21320 --- netbox/dcim/models/racks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/dcim/models/racks.py b/netbox/dcim/models/racks.py index 89952492d..c4eaa7e20 100644 --- a/netbox/dcim/models/racks.py +++ b/netbox/dcim/models/racks.py @@ -373,7 +373,7 @@ class Rack(ContactsMixin, ImageAttachmentsMixin, TrackingModelMixin, RackBase): super().clean() # Validate location/site assignment - if self.site and self.location and self.location.site != self.site: + if self.site_id and self.location_id and self.location.site_id != self.site_id: raise ValidationError(_("Assigned location must belong to parent site ({site}).").format(site=self.site)) # Validate outer dimensions and unit