From 2883fa14de3f7cd089ff5c98cd598ebb3dbe7387 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Mon, 3 Apr 2023 12:22:36 -0700 Subject: [PATCH] Fixes #12074: Move automatic location assignment out of clean() * 12074 fix full clean * 12074 move device location setting to save from clean * 12074 fix set location only if present in rack * Update base.py --------- Co-authored-by: Jeremy Stretch --- netbox/dcim/models/devices.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 603129228..1429003c5 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -659,8 +659,6 @@ class Device(PrimaryModel, ConfigContextModel): raise ValidationError({ 'rack': f"Rack {self.rack} does not belong to location {self.location}.", }) - elif self.rack: - self.location = self.rack.location if self.rack is None: if self.face: @@ -801,6 +799,9 @@ class Device(PrimaryModel, ConfigContextModel): if is_new and not self.airflow: self.airflow = self.device_type.airflow + if self.rack and self.rack.location: + self.location = self.rack.location + super().save(*args, **kwargs) # If this is a new Device, instantiate all the related components per the DeviceType definition