From ca20ff6b7bc496e5cc9d0952ed1022bbeb5b1c2d Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 26 Nov 2024 14:26:06 -0500 Subject: [PATCH] Fixes #17810: Fix assignment of device to rack via REST API without specifying position/face --- ..._device_adjust_rack_position_constraint.py | 30 +++++++++++++++++++ netbox/dcim/models/devices.py | 1 + 2 files changed, 31 insertions(+) create mode 100644 netbox/dcim/migrations/0192_device_adjust_rack_position_constraint.py diff --git a/netbox/dcim/migrations/0192_device_adjust_rack_position_constraint.py b/netbox/dcim/migrations/0192_device_adjust_rack_position_constraint.py new file mode 100644 index 00000000000..131db6a795f --- /dev/null +++ b/netbox/dcim/migrations/0192_device_adjust_rack_position_constraint.py @@ -0,0 +1,30 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0191_module_bay_rebuild'), + ('extras', '0121_customfield_related_object_filter'), + ('ipam', '0070_vlangroup_vlan_id_ranges'), + ('tenancy', '0015_contactassignment_rename_content_type'), + ('virtualization', '0040_convert_disk_size'), + ] + + operations = [ + migrations.RemoveConstraint( + model_name='device', + name='dcim_device_unique_rack_position_face', + ), + migrations.AddConstraint( + model_name='device', + constraint=models.UniqueConstraint( + condition=models.Q( + ('position__isnull', False), + ('rack__isnull', False) + ), + fields=('rack', 'position', 'face'), + name='dcim_device_unique_rack_position_face' + ), + ), + ] diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index 0f11cb5f30a..a20912294ff 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -798,6 +798,7 @@ class Meta: ), models.UniqueConstraint( fields=('rack', 'position', 'face'), + condition=Q(rack__isnull=False, position__isnull=False), name='%(app_label)s_%(class)s_unique_rack_position_face' ), models.UniqueConstraint(