From e4ecd2dae9dcb7990123947881f3c18e92c838a2 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 19 Mar 2021 10:22:30 -0400 Subject: [PATCH] Fixes #6006: Fix VLAN group/site association for bulk prefix import --- docs/release-notes/version-2.10.md | 1 + netbox/ipam/forms.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/release-notes/version-2.10.md b/docs/release-notes/version-2.10.md index 82af48355..f50a9814e 100644 --- a/docs/release-notes/version-2.10.md +++ b/docs/release-notes/version-2.10.md @@ -9,6 +9,7 @@ * [#5962](https://github.com/netbox-community/netbox/issues/5962) - Ensure consistent display of change log action labels * [#5966](https://github.com/netbox-community/netbox/issues/5966) - Skip Markdown reference link when tabbing through form fields * [#5977](https://github.com/netbox-community/netbox/issues/5977) - Correct validation of `RELEASE_CHECK_URL` config parameter +* [#6006](https://github.com/netbox-community/netbox/issues/6006) - Fix VLAN group/site association for bulk prefix import --- diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index e2cb51417..a12e5f94f 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -465,12 +465,14 @@ class PrefixCSVForm(CustomFieldModelCSVForm): if data: - # Limit vlan queryset by assigned site and group - params = { - f"site__{self.fields['site'].to_field_name}": data.get('site'), - f"group__{self.fields['vlan_group'].to_field_name}": data.get('vlan_group'), - } - self.fields['vlan'].queryset = self.fields['vlan'].queryset.filter(**params) + # Limit VLAN queryset by assigned site and/or group (if specified) + params = {} + if data.get('site'): + params[f"site__{self.fields['site'].to_field_name}"] = data.get('site') + if data.get('vlan_group'): + params[f"group__{self.fields['vlan_group'].to_field_name}"] = data.get('vlan_group') + if params: + self.fields['vlan'].queryset = self.fields['vlan'].queryset.filter(**params) class PrefixBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):