Преглед изворни кода

Fixes #11796: When importing devices, restrict rack by location only if the location field is specified

jeremystretch пре 3 година
родитељ
комит
ed77c03830
2 измењених фајлова са 9 додато и 2 уклоњено
  1. 4 0
      docs/release-notes/version-3.4.md
  2. 5 2
      netbox/dcim/forms/bulk_import.py

+ 4 - 0
docs/release-notes/version-3.4.md

@@ -2,6 +2,10 @@
 
 ## v3.4.6 (FUTURE)
 
+### Bug Fixes
+
+* [#11796](https://github.com/netbox-community/netbox/issues/11796) - When importing devices, restrict rack by location only if the location field is specified
+
 ---
 
 ## v3.4.5 (2023-02-21)

+ 5 - 2
netbox/dcim/forms/bulk_import.py

@@ -447,11 +447,14 @@ class DeviceImportForm(BaseDeviceImportForm):
             self.fields['location'].queryset = self.fields['location'].queryset.filter(**params)
             self.fields['parent'].queryset = self.fields['parent'].queryset.filter(**params)
 
-            # Limit rack queryset by assigned site and group
+            # Limit rack queryset by assigned site and location
             params = {
                 f"site__{self.fields['site'].to_field_name}": data.get('site'),
-                f"location__{self.fields['location'].to_field_name}": data.get('location'),
             }
+            if 'location' in data:
+                params.update({
+                    f"location__{self.fields['location'].to_field_name}": data.get('location'),
+                })
             self.fields['rack'].queryset = self.fields['rack'].queryset.filter(**params)
 
             # Limit device bay queryset by parent device