From 7439faad34301eb3dc546aea79d42ea79c4e6fe9 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 9 Apr 2021 09:56:36 -0400 Subject: [PATCH] Fixes #6123: Prevent device from being assigned to mismatched site and location --- docs/release-notes/version-2.11.md | 1 + netbox/dcim/models/devices.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index d2ccb5282..6a6b7f78a 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -16,6 +16,7 @@ * [#6106](https://github.com/netbox-community/netbox/issues/6106) - Allow assigning a virtual interface as the parent of an existing interface * [#6107](https://github.com/netbox-community/netbox/issues/6107) - Fix rack selection field on device form * [#6110](https://github.com/netbox-community/netbox/issues/6110) - Fix handling of TemplateColumn values for table export +* [#6123](https://github.com/netbox-community/netbox/issues/6123) - Prevent device from being assigned to mismatched site and location * [#6130](https://github.com/netbox-community/netbox/issues/6130) - Improve display of assigned models in custom fields list --- diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index a5efadac5..551fac2d4 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -652,6 +652,10 @@ class Device(PrimaryModel, ConfigContextModel): raise ValidationError({ 'rack': f"Rack {self.rack} does not belong to site {self.site}.", }) + if self.location and self.site != self.location.site: + raise ValidationError({ + 'location': f"Location {self.location} does not belong to site {self.site}.", + }) if self.rack and self.location and self.rack.location != self.location: raise ValidationError({ 'rack': f"Rack {self.rack} does not belong to location {self.location}.",