Skip to content

Virtual chassis search displays duplicate entries #6010

@maximumG

Description

@maximumG

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

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions