Virtual chassis search displays duplicate entries #4679

Closed
opened 2025-12-29 19:19:25 +01:00 by adam · 5 comments
Owner

Originally created by @maximumG on GitHub (Mar 18, 2021).

Originally assigned to: @maximumG on GitHub.

NetBox version

v2.10.6

Python version

3.8

Steps to Reproduce

  1. Create a device named test-vc-1-1
  2. Create a device named test-vc-1-2
  3. Create a virtual chassis named test-vc-1 and bundle the two device created in 1. and 2.
  4. In the virtual chassis view perform a search by name using test-vc-1

Expected Behavior

The list view should display only one entry for the virtual chassis (check the screenshot of the search using Nebox 2.9 release)

Observed Behavior

The list view displays twice the same entry for the virtual chassis, one per member (check the screenshot of the search using Nebox 2.10.6 release)

Expected behaviour in netbox 2.9

Netbox 2.9

Observed behaviour in netbox 2.10

image

Solution hint

After some code investigation it seems that the VirtualChassisFilterSet.search method in dcim/filter.py has something wrong with the forged queryset.

    def search(self, queryset, name, value):
        if not value.strip():
            return queryset
        qs_filter = (
            Q(name__icontains=value) |
            Q(members__name__icontains=value) |
            Q(domain__icontains=value)
        )
        return queryset.filter(qs_filter)

When you modify the queryset with the following code, the entry is not duplicated anymore in the WebUI.

    def search(self, queryset, name, value):
        if not value.strip():
            return queryset
        qs_filter = (
            Q(name__icontains=value) |
            Q(members__name__icontains=value) |
            Q(domain__icontains=value)
        )
        return queryset.filter(qs_filter).distinct() # adding distinct de-duplicate the VC
Originally created by @maximumG on GitHub (Mar 18, 2021). Originally assigned to: @maximumG on GitHub. ### NetBox version v2.10.6 ### Python version 3.8 ### Steps to Reproduce 1. Create a device named test-vc-1-1 2. Create a device named test-vc-1-2 3. Create a virtual chassis named test-vc-1 and bundle the two device created in 1. and 2. 4. In the virtual chassis view perform a search by name using test-vc-1 ### Expected Behavior The list view should display only one entry for the virtual chassis (check the screenshot of the search using Nebox 2.9 release) ### Observed Behavior The list view displays twice the same entry for the virtual chassis, one per member (check the screenshot of the search using Nebox 2.10.6 release) ### Expected behaviour in netbox 2.9 ![Netbox 2.9](https://user-images.githubusercontent.com/4469833/111668228-d558f600-8815-11eb-9e81-def201f1e744.png) ### Observed behaviour in netbox 2.10 ![image](https://user-images.githubusercontent.com/4469833/111668410-033e3a80-8816-11eb-8768-78493606ad7c.png) ### Solution hint After some code investigation it seems that the `VirtualChassisFilterSet.search` method in `dcim/filter.py` has something wrong with the [forged queryset](https://github.com/netbox-community/netbox/blob/91fe80f73c12bb4182ee892ca612252e9a30126b/netbox/dcim/filters.py#L1078). ```python def search(self, queryset, name, value): if not value.strip(): return queryset qs_filter = ( Q(name__icontains=value) | Q(members__name__icontains=value) | Q(domain__icontains=value) ) return queryset.filter(qs_filter) ``` When you modify the queryset with the following code, the entry is not duplicated anymore in the WebUI. ```python def search(self, queryset, name, value): if not value.strip(): return queryset qs_filter = ( Q(name__icontains=value) | Q(members__name__icontains=value) | Q(domain__icontains=value) ) return queryset.filter(qs_filter).distinct() # adding distinct de-duplicate the VC ```
adam added the type: bugstatus: accepted labels 2025-12-29 19:19:25 +01:00
adam closed this issue 2025-12-29 19:19:25 +01:00
Author
Owner

@jmanteau commented on GitHub (Mar 18, 2021):

I confirm to have seen the same behavior and I indeed would like have it fixed as well ! Nice finding !

@jmanteau commented on GitHub (Mar 18, 2021): I confirm to have seen the same behavior and I indeed would like have it fixed as well ! Nice finding !
Author
Owner

@ziggekatten commented on GitHub (Mar 18, 2021):

Yep, funny enough I was demoing netbox for a colleague today and experienced this as well.

We are running 2.10.6

@ziggekatten commented on GitHub (Mar 18, 2021): Yep, funny enough I was demoing netbox for a colleague today and experienced this as well. We are running 2.10.6
Author
Owner

@thomas-rotszyld commented on GitHub (Mar 19, 2021):

same problem here !!! easy fix

@thomas-rotszyld commented on GitHub (Mar 19, 2021): same problem here !!! easy fix
Author
Owner

@jeremystretch commented on GitHub (Mar 19, 2021):

Open for volunteers

@jeremystretch commented on GitHub (Mar 19, 2021): Open for volunteers
Author
Owner

@maximumG commented on GitHub (Mar 19, 2021):

@jeremystretch I can take the lead on this one if you agree. Quick and easy fix.

@maximumG commented on GitHub (Mar 19, 2021): @jeremystretch I can take the lead on this one if you agree. Quick and easy fix.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4679