fix(dcim): Validate location/site relationship using FK IDs
CI / build (20.x, 3.12) (push) Failing after 17s
CI / build (20.x, 3.13) (push) Failing after 15s
CI / build (20.x, 3.14) (push) Failing after 14s

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
This commit is contained in:
Martin Hauser
2026-02-02 21:06:19 +01:00
parent c060eef1d8
commit 75106e1cca
+1 -1
View File
@@ -373,7 +373,7 @@ class Rack(ContactsMixin, ImageAttachmentsMixin, TrackingModelMixin, RackBase):
super().clean() super().clean()
# Validate location/site assignment # 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)) raise ValidationError(_("Assigned location must belong to parent site ({site}).").format(site=self.site))
# Validate outer dimensions and unit # Validate outer dimensions and unit