Scoped VLAN Groups do not appear in Related Objects #6841

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

Originally created by @foxx on GitHub (Aug 19, 2022).

NetBox version

v3.3.0

Python version

3.9

Steps to Reproduce

  1. Create multiple sites and a site group to contain them
  2. Create a VLAN Group scoped to that Site Group
  3. Look at Related Objects for any site within that Site Group
  4. It will show no associated VLAN Groups

Expected Behavior

Related Objects for a site should be inherited from any object which is scoped to the Site Group that site is part of.

Observed Behavior

No related objects appeared.

I think this was introduced as of:
https://github.com/netbox-community/netbox/issues/5284

Originally created by @foxx on GitHub (Aug 19, 2022). ### NetBox version v3.3.0 ### Python version 3.9 ### Steps to Reproduce 1. Create multiple sites and a site group to contain them 2. Create a VLAN Group scoped to that Site Group 3. Look at Related Objects for any site within that Site Group 4. It will show no associated VLAN Groups ### Expected Behavior Related Objects for a site should be inherited from any object which is scoped to the Site Group that site is part of. ### Observed Behavior No related objects appeared. I think this was introduced as of: https://github.com/netbox-community/netbox/issues/5284
adam closed this issue 2025-12-29 19:45:57 +01:00
Author
Owner

@foxx commented on GitHub (Aug 20, 2022):

I've had a look through the code and it seems to be related to this.

class SiteViewSet(NetBoxModelViewSet):
    queryset = Site.objects.prefetch_related(
        'region', 'tenant', 'asns', 'tags'
    ).annotate(
        device_count=count_related(Device, 'site'),
        rack_count=count_related(Rack, 'site'),
        prefix_count=count_related(Prefix, 'site'),
        vlan_count=count_related(VLAN, 'site'),
        circuit_count=count_related(Circuit, 'terminations__site'),
        virtualmachine_count=count_related(VirtualMachine, 'cluster__site')
    )
    serializer_class = serializers.SiteSerializer
    filterset_class = filtersets.SiteFilterSet

It seems like it's only counting objects which have direct relation to site while ignoring site_group. Sadly I'm not familiar enough with the code base to quickly figure out how to make it include related objects, which presumably would extend beyond just counting related objects (e.g. the view which you click through to on the number).

If one of the maintainers could jump in with some pointers then I'll gladly put together a PR. Also any feedback on whether this would be accepted as a bug fix would be appreciated.

@foxx commented on GitHub (Aug 20, 2022): I've had a look through the code and it seems to be related to [this](https://github.com/netbox-community/netbox/blob/develop/netbox/dcim/api/views.py#L134). ```python class SiteViewSet(NetBoxModelViewSet): queryset = Site.objects.prefetch_related( 'region', 'tenant', 'asns', 'tags' ).annotate( device_count=count_related(Device, 'site'), rack_count=count_related(Rack, 'site'), prefix_count=count_related(Prefix, 'site'), vlan_count=count_related(VLAN, 'site'), circuit_count=count_related(Circuit, 'terminations__site'), virtualmachine_count=count_related(VirtualMachine, 'cluster__site') ) serializer_class = serializers.SiteSerializer filterset_class = filtersets.SiteFilterSet ``` It seems like it's only counting objects which have direct relation to `site` while ignoring `site_group`. Sadly I'm not familiar enough with the code base to quickly figure out how to make it include related objects, which presumably would extend beyond just counting related objects (e.g. the view which you click through to on the number). If one of the maintainers could jump in with some pointers then I'll gladly put together a PR. Also any feedback on whether this would be accepted as a bug fix would be appreciated.
Author
Owner

@jeremystretch commented on GitHub (Aug 22, 2022):

This is expected behavior. The site view does not report any associated VLAN groups, because the VLAN group you created is assigned to the site group, not to the individual site. This statistic includes only VLAN groups assigned to the site being viewed.

I've had a look through the code and it seems to be related to this.

FYI that code is for the REST API view. UI views are under dcim/views.py.

@jeremystretch commented on GitHub (Aug 22, 2022): This is expected behavior. The site view does not report any associated VLAN groups, because the VLAN group you created is assigned to the site group, not to the individual site. This statistic includes only VLAN groups assigned to the site being viewed. > I've had a look through the code and it seems to be related to [this](https://github.com/netbox-community/netbox/blob/develop/netbox/dcim/api/views.py#L134). FYI that code is for the REST API view. UI views are under `dcim/views.py`.
Author
Owner

@foxx commented on GitHub (Aug 23, 2022):

Ahh understood, thanks for the quick reply!

@foxx commented on GitHub (Aug 23, 2022): Ahh understood, thanks for the quick reply!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6841