VLANGroup CSV import incorrectly states 'site' as a column #5154

Closed
opened 2025-12-29 19:24:51 +01:00 by adam · 3 comments
Owner

Originally created by @sdktr on GitHub (Aug 6, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v.2.11.10

Python version

3.8

Steps to Reproduce

Open VlanGroup CSV import (https://demo.netbox.dev/ipam/vlan-groups/import/)

Expected Behavior

Valid columns are displayed as option in helper table

Observed Behavior

According to https://github.com/netbox-community/netbox/discussions/6897 'site' should not be directly referenced. Since v2.11 we expect a scope_type and scope_id

Originally created by @sdktr on GitHub (Aug 6, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v.2.11.10 ### Python version 3.8 ### Steps to Reproduce Open VlanGroup CSV import (https://demo.netbox.dev/ipam/vlan-groups/import/) ### Expected Behavior Valid columns are displayed as option in helper table ### Observed Behavior According to https://github.com/netbox-community/netbox/discussions/6897 'site' should not be directly referenced. Since v2.11 we expect a scope_type and scope_id
adam added the type: bugstatus: accepted labels 2025-12-29 19:24:51 +01:00
adam closed this issue 2025-12-29 19:24:51 +01:00
Author
Owner

@candlerb commented on GitHub (Aug 7, 2021):

The spurious "site" column probably comes from VLANGroupCSVForm.

@candlerb commented on GitHub (Aug 7, 2021): The spurious "site" column probably comes from [VLANGroupCSVForm](https://github.com/netbox-community/netbox/blob/v2.11.10/netbox/ipam/forms.py#L1240-L1251).
Author
Owner

@sdktr commented on GitHub (Aug 7, 2021):

The spurious "site" column probably comes from VLANGroupCSVForm.

I assumed as well. But not sure how that form is supposed to look. Maybe deleting the site reference is enough to fix both this bug and https://github.com/netbox-community/netbox/issues/6910 but my guess is that one requires some other fixes to the form as well.

@sdktr commented on GitHub (Aug 7, 2021): > The spurious "site" column probably comes from [VLANGroupCSVForm](https://github.com/netbox-community/netbox/blob/v2.11.10/netbox/ipam/forms.py#L1240-L1251). I assumed as well. But not sure how that form is supposed to look. Maybe deleting the site reference is enough to fix both this bug and https://github.com/netbox-community/netbox/issues/6910 but my guess is that one requires some other fixes to the form as well.
Author
Owner

@candlerb commented on GitHub (Aug 7, 2021):

The nearest existing working code I can find with GenericForeignKey is assigned_object_type and assigned_object_id in IPAddress.

However, IPAddressCSVForm does not have separate fields for assigned_object_type and assigned_object_id; it just has interface, and internally the queryset is updated to either Interface.objects.filter(...) or VMInterface.objects.filter(...) as appropriate.

I also note that the way IPAddress limits its models:

    assigned_object_type = models.ForeignKey(
        to=ContentType,
        limit_choices_to=IPADDRESS_ASSIGNMENT_MODELS,

# where
IPADDRESS_ASSIGNMENT_MODELS = Q(
    Q(app_label='dcim', model='interface') |
    Q(app_label='virtualization', model='vminterface')
)

is slightly different to how VLANGroup does it:

    scope_type = models.ForeignKey(
        to=ContentType,
        ...
        limit_choices_to=Q(model__in=VLANGROUP_SCOPE_TYPES),

# where
VLANGROUP_SCOPE_TYPES = (
    'region', 'sitegroup', 'site', 'location', 'rack', 'clustergroup', 'cluster',
)

But this is all deep Django magic to me.

@candlerb commented on GitHub (Aug 7, 2021): The nearest existing working code I can find with GenericForeignKey is `assigned_object_type` and `assigned_object_id` in [IPAddress](https://github.com/netbox-community/netbox/blob/v2.11.10/netbox/ipam/models/ip.py#L561-L576). However, IPAddressCSVForm does not have separate fields for assigned_object_type and assigned_object_id; it just has [interface](https://github.com/netbox-community/netbox/blob/v2.11.10/netbox/ipam/models/ip.py#L561-L576), and internally the queryset is [updated](https://github.com/netbox-community/netbox/blob/v2.11.10/netbox/ipam/forms.py#L976-L985) to either `Interface.objects.filter(...)` or `VMInterface.objects.filter(...)` as appropriate. I also note that the way IPAddress limits its models: ``` assigned_object_type = models.ForeignKey( to=ContentType, limit_choices_to=IPADDRESS_ASSIGNMENT_MODELS, # where IPADDRESS_ASSIGNMENT_MODELS = Q( Q(app_label='dcim', model='interface') | Q(app_label='virtualization', model='vminterface') ) ``` is slightly different to how VLANGroup does it: ``` scope_type = models.ForeignKey( to=ContentType, ... limit_choices_to=Q(model__in=VLANGROUP_SCOPE_TYPES), # where VLANGROUP_SCOPE_TYPES = ( 'region', 'sitegroup', 'site', 'location', 'rack', 'clustergroup', 'cluster', ) ``` But this is all deep Django magic to me.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5154