Repository: netbox-community/netbox

Issue:
Cannot add tagged VLAN from other site on multiple port edit
### NetBox version

v3.4.2

### Python version

3.8

### Steps to Reproduce

I have come across an issue adding VLANs to an interface if I arrive at the interfrace configuration page from the  DEVICES -> Device Components -> Interfaces page, and try to edit multiple interface from the list (on the same device). I can only add VLANs as tagged VLANs if they are allocated to the same Site as the Device. This issue does not exist if I go to the Device Page and from there the Interfaces sub-page.

1. Create Site "SITE_TEST"
2. Create vlan 10 in Site "SITE_TEST"
3. Create vlan 20 in no Site
4. Create a device "DEV_TEST" in Site "SITE_TEST" with at leasttwo interfaces
5. Navigate to DEVICES -> Device Components -> Interfaces
6. Filter for all interfaces from device "DEV_TEST"
7. OK: Edit single interface -> 802.1Q Switching Mode: Tagged -> Tagged VLANs includes  VLAN 10 and 20 -> as expected
8. NOK: Edit multiple interfaces -> 802.1Q Switching Mode: Tagged -> Tagged VLANs includes ony  VLAN 10 -> not expected

### Expected Behavior

Same behavior between "Device -> Interfaces sub-page" and "DEVICES -> Device Components -> Interfaces + filter for a device"

### Observed Behavior

"Device -> Interfaces sub-page" - I can add VLANs from same site or VLANs without Site assigned
"DEVICES -> Device Components -> Interfaces + filter for a device" - I can only add VLANs from same Site as Device


Discussion:
This bug is also present in editing a prefix. Only site specific VLANs are shown - not site-less VLANs.
I guess because the site field for the prefix is also a filter for the VLAN field.
If should always list site-specific VLANs and site-less VLANs (for example if you want prefixes to be assigned to a site but not VLANs)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
I'm interested in taking ownership of this issue.

I've ran into this before while using NetBox and would like to see it fixed.
I opened https://github.com/netbox-community/netbox/issues/12622 to track a related bug that impacts the creation and import of prefixes in IPAM. The fix for that issue is different than what will be required for this issue. 

Resolving patch:
diff --git a/netbox/dcim/forms/bulk_edit.py b/netbox/dcim/forms/bulk_edit.py
--- a/netbox/dcim/forms/bulk_edit.py
+++ b/netbox/dcim/forms/bulk_edit.py
@@ -1,4 +1,5 @@
 from django import forms
+from django.conf import settings
 from django.contrib.auth.models import User
 from django.utils.translation import gettext as _
 from timezone_field import TimeZoneFormField
@@ -1292,8 +1293,13 @@ def __init__(self, *args, **kwargs):
                         break
 
                 if site is not None:
-                    self.fields['untagged_vlan'].widget.add_query_param('site_id', site.pk)
-                    self.fields['tagged_vlans'].widget.add_query_param('site_id', site.pk)
+                    # Query for VLANs assigned to the same site and VLANs with no site assigned (null).
+                    self.fields['untagged_vlan'].widget.add_query_param(
+                        'site_id', [site.pk, settings.FILTERS_NULL_CHOICE_VALUE]
+                    )
+                    self.fields['tagged_vlans'].widget.add_query_param(
+                        'site_id', [site.pk, settings.FILTERS_NULL_CHOICE_VALUE]
+                    )
 
             self.fields['parent'].choices = ()
             self.fields['parent'].widget.attrs['disabled'] = True


Test patch: