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 <jstretch@netboxlabs.com>
This commit is contained in:
Arthur Hanson 2023-04-03 12:22:36 -07:00 committed by GitHub
parent 3264636b7a
commit 2883fa14de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -659,8 +659,6 @@ class Device(PrimaryModel, ConfigContextModel):
raise ValidationError({ raise ValidationError({
'rack': f"Rack {self.rack} does not belong to location {self.location}.", '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.rack is None:
if self.face: if self.face:
@ -801,6 +799,9 @@ class Device(PrimaryModel, ConfigContextModel):
if is_new and not self.airflow: if is_new and not self.airflow:
self.airflow = self.device_type.airflow self.airflow = self.device_type.airflow
if self.rack and self.rack.location:
self.location = self.rack.location
super().save(*args, **kwargs) super().save(*args, **kwargs)
# If this is a new Device, instantiate all the related components per the DeviceType definition # If this is a new Device, instantiate all the related components per the DeviceType definition