Location List and Locations not Showing Associated VLAN Groups #10811

Closed
opened 2025-12-29 21:36:12 +01:00 by adam · 3 comments
Owner

Originally created by @Kurnugia on GitHub (Feb 26, 2025).

Originally assigned to: @bctiemann, @renatoalmeidaoliveira on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.2.3

Python Version

3.12

Steps to Reproduce

  1. Create a Site.
  2. Create a Location within that Site.
  3. Create a VLAN Group and any constituent VLANs.
  4. Assign the VLAN Group to the Location.
  5. View the list of Locations.
  6. View the Location with the VLAN Group assigned.

Expected Behavior

Viewing the Location List

  • When viewing the list of Locations, we should be able to see any reference to the associated VLAN Group(s).

Viewing the Location Itself

  • When viewing the Location itself, we should be able to see any reference to the assigned VLAN Group(s) in the Related Objects list at the right.

Image

Observed Behavior

We do not see any reference to any VLAN Groups anywhere other than when viewing IPAM > VLAN Groups. This makes it difficult to see which VLAN Groups are defined for different locations within a site.


Potential Resolutions

I tried to resolve some of this, but I don't have enough knowledge/experience with the coding of NetBox.

Location List

File: /opt/netbox/netbox/dcim/tables/sites.py

Changes:

class LocationTable ...
    ...
    vlan_groups = tables.ManyToManyColumn(
        verbose_name=_("VLAN Groups"),
        linkify_item=True,
    )
    class Meta(NetBoxTable.Meta):
        model = Location
        fields = (
            'pk', 'id', 'name', 'site', 'status', 'facility', 'tenant', 'tenant_group', 'rack_count', 'device_count',
            'description', 'slug', 'contacts', 'tags', 'actions', 'created', 'last_updated', "vlan_groups",
        )

This would result in the following:

Image

Location

I was unable to figure out how to update the Related Objects field when looking at a Location to view the associated VLAN Groups.

Originally created by @Kurnugia on GitHub (Feb 26, 2025). Originally assigned to: @bctiemann, @renatoalmeidaoliveira on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.2.3 ### Python Version 3.12 ### Steps to Reproduce 1. Create a Site. 2. Create a Location within that Site. 3. Create a VLAN Group and any constituent VLANs. 4. Assign the VLAN Group to the Location. 5. View the list of Locations. 6. View the Location with the VLAN Group assigned. ### Expected Behavior ### Viewing the Location List - When viewing the list of Locations, we should be able to see any reference to the associated VLAN Group(s). ### Viewing the Location Itself - When viewing the Location itself, we should be able to see any reference to the assigned VLAN Group(s) in the `Related Objects` list at the right. ![Image](https://github.com/user-attachments/assets/4f19242e-6840-41f9-a8b2-0413e65d8104) ### Observed Behavior We do not see any reference to any VLAN Groups anywhere other than when viewing `IPAM > VLAN Groups`. This makes it difficult to see which VLAN Groups are defined for different locations within a site. --- ### Potential Resolutions I tried to resolve some of this, but I don't have enough knowledge/experience with the coding of NetBox. #### Location List File: `/opt/netbox/netbox/dcim/tables/sites.py` Changes: ```python class LocationTable ... ... vlan_groups = tables.ManyToManyColumn( verbose_name=_("VLAN Groups"), linkify_item=True, ) class Meta(NetBoxTable.Meta): model = Location fields = ( 'pk', 'id', 'name', 'site', 'status', 'facility', 'tenant', 'tenant_group', 'rack_count', 'device_count', 'description', 'slug', 'contacts', 'tags', 'actions', 'created', 'last_updated', "vlan_groups", ) ``` This would result in the following: ![Image](https://github.com/user-attachments/assets/9845282a-6042-47bd-80f8-3bf9e9580554) #### Location I was unable to figure out how to update the `Related Objects` field when looking at a Location to view the associated VLAN Groups.
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:36:12 +01:00
adam closed this issue 2025-12-29 21:36:12 +01:00
Author
Owner

@bctiemann commented on GitHub (Feb 27, 2025):

This seems like we might need to revisit this code here:

https://github.com/netbox-community/netbox/blob/main/netbox/utilities/relations.py#L8-L17

We rely on model._meta.related_objects to give us the list of related objects for a given model, and it only contains ManyToOneRel relations. Location.vlan_groups is a GenericRelation which does not show up in model._meta.related_objects, nor does it seem to be available in any other obvious place in _meta (there is private_fields, but that doesn't seem safe).

We may need to come up with another approach for this such as adding fields in a model's Meta to be additionally listed in "Related Objects" beyond the ones returned by the above code. But that feels like more of a feature request than a bug.

@bctiemann commented on GitHub (Feb 27, 2025): This seems like we might need to revisit this code here: https://github.com/netbox-community/netbox/blob/main/netbox/utilities/relations.py#L8-L17 We rely on `model._meta.related_objects` to give us the list of related objects for a given model, and it only contains `ManyToOneRel` relations. `Location.vlan_groups` is a `GenericRelation` which does not show up in `model._meta.related_objects`, nor does it seem to be available in any other obvious place in `_meta` (there is `private_fields`, but that doesn't seem safe). We may need to come up with another approach for this such as adding fields in a model's `Meta` to be additionally listed in "Related Objects" beyond the ones returned by the above code. But that feels like more of a feature request than a bug.
Author
Owner

@bctiemann commented on GitHub (Feb 27, 2025):

This functionality is handled by passing extra fields to the get_related_models method here:

b9b42cd3b4/netbox/dcim/views.py (L530-L552)

VLAN groups can be added to Related Objects by adding this:

                    (VLANGroup.objects.restrict(request.user, 'view').filter(location=instance), 'location'),

However, I think this would be better handled as a feature request rather than a bug, as this is basically just adding a field to a listing in an understood way, and the only point of contention would be whether it's a valuable enough addition.

@bctiemann commented on GitHub (Feb 27, 2025): This functionality is handled by passing `extra` fields to the `get_related_models` method here: https://github.com/netbox-community/netbox/blob/b9b42cd3b44a6857b2c86f8f566100288abe2573/netbox/dcim/views.py#L530-L552 VLAN groups can be added to Related Objects by adding this: ``` (VLANGroup.objects.restrict(request.user, 'view').filter(location=instance), 'location'), ``` However, I think this would be better handled as a feature request rather than a bug, as this is basically just adding a field to a listing in an understood way, and the only point of contention would be whether it's a valuable enough addition.
Author
Owner

@bctiemann commented on GitHub (Feb 28, 2025):

@Kurnugia Actually on further thought this does seem like a bug -- this is not expected behavior. The intent is for ALL related objects (except for certain explicitly omitted ones) to appear automatically in that list, and VLAN groups should be showing up there.

None of the GenericRelations that have been added to various models since the introduction of scoping will have been added to Related Objects in this way, and so an ideal fix would be to add them explicitly (as in my previous comment) to all affected models, of which there might be quite a few.

@bctiemann commented on GitHub (Feb 28, 2025): @Kurnugia Actually on further thought this does seem like a bug -- this is not expected behavior. The intent is for ALL related objects (except for certain explicitly omitted ones) to appear automatically in that list, and VLAN groups should be showing up there. None of the `GenericRelation`s that have been added to various models since the introduction of scoping will have been added to Related Objects in this way, and so an ideal fix would be to add them explicitly (as in my previous comment) to all affected models, of which there might be quite a few.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10811