Repository: netbox-community/netbox

Issue:
Bulk editing of interface 802.1Q settings results in incorrect form validation.
<!--
    Before opening a new issue, please search through the existing issues to
    see if your topic has already been addressed. Note that you may need to
    remove the "is:open" filter from the search bar to include closed issues.

    Check the appropriate type for your issue below by placing an x between the
    brackets. For assistance with installation issues, or for any other issues
    other than those listed below, please raise your topic for discussion on
    our mailing list:

        https://groups.google.com/forum/#!forum/netbox-discuss

    Please note that issues which do not fall under any of the below categories
    will be closed. Due to an excessive backlog of feature requests, we are
    not currently accepting any proposals which extend NetBox's feature scope.

    Do not prepend any sort of tag to your issue's title. An administrator will
    review your issue and assign labels as appropriate.
--->
### Issue type
[ ] Feature request <!-- An enhancement of existing functionality -->
[ x ] Bug report      <!-- Unexpected or erroneous behavior -->
[ ] Documentation   <!-- A modification to the documentation -->

<!--
    Please describe the environment in which you are running NetBox. (Be sure
    to verify that you are running the latest stable release of NetBox before
    submitting a bug report.) If you are submitting a bug report and have made
    any changes to the code base, please first validate that your bug can be
    recreated while running an official release.
-->
### Environment
* Python version:  2.7
* NetBox version:  develop-2.3

<!--
    BUG REPORTS must include:
        * A list of the steps needed for someone else to reproduce the bug
        * A description of the expected and observed behavior
        * Any relevant error messages (screenshots may also help)

    FEATURE REQUESTS must include:
        * A detailed description of the proposed functionality
        * A use case for the new feature
        * A rough description of any necessary changes to the database schema
        * Any relevant third-party libraries which would be needed
-->
### Description
Bulk editing of interface 802.1Q settings results in incorrect form validation. The `InterfaceBulkEditForm` is only accounting for initial data for 802.1Q fields and thus bombs validation because no device context on form post. The interface create and edit forms do this correctly.





Discussion:

Resolving patch:
diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py
--- a/netbox/dcim/forms.py
+++ b/netbox/dcim/forms.py
@@ -1934,6 +1934,11 @@ def __init__(self, *args, **kwargs):
                 device = Device.objects.get(pk=self.initial.get('device'))
             except Device.DoesNotExist:
                 pass
+        else:
+            try:
+                device = Device.objects.get(pk=self.data.get('device'))
+            except Device.DoesNotExist:
+                pass
         if device is not None:
             interface_ordering = device.device_type.interface_ordering
             self.fields['lag'].queryset = Interface.objects.order_naturally(method=interface_ordering).filter(
@@ -1950,10 +1955,16 @@ def __init__(self, *args, **kwargs):
             self.fields['site'].queryset = Site.objects.none()
             self.fields['site'].initial = None
 
-        filter_dict = {
-            'group_id': None,
-            'site_id': None,
-        }
+        if self.is_bound:
+            filter_dict = {
+                'group_id': self.data.get('vlan_group') or None,
+                'site_id': self.data.get('site') or None,
+            }
+        else:
+            filter_dict = {
+                'group_id': None,
+                'site_id': None,
+            }
 
         self.fields['untagged_vlan'].queryset = VLAN.objects.filter(**filter_dict)
         self.fields['tagged_vlans'].queryset = VLAN.objects.filter(**filter_dict)
@@ -2324,4 +2335,4 @@ def clean_vc_position(self):
         if Device.objects.filter(virtual_chassis=self.instance.virtual_chassis, vc_position=vc_position).exists():
             raise forms.ValidationError("A virtual chassis member already exists in this position.")
 
-        return vc_position
\ No newline at end of file
+        return vc_position


Test patch: