Skip to content

filter present_in_vrf_id returning more results than expected #17362

Closed
@pl0xym0r

Description

@pl0xym0r

Deployment Type

Self-hosted

NetBox Version

v4.0.10

Python Version

3.11

Steps to Reproduce

1 Use the data from https://github.com/netbox-community/netbox-demo-data
2 Add prefix in VRF shared
3 Use ipam/prefixes/?present_in_vrf_id=5 (echo VRF) to have all prefixes from Shared and Echo VRF

Expected Behavior

A display of all prefixes seen from Echo VRF point of view

Observed Behavior

All prefixes from Echo VRF are displayed twice
It seems the union of querysets returns twice the value of the VRF in parameter :

def filter_present_in_vrf(self, queryset, name, vrf):

image

tested into nbshell itself :

echo=VRF.objects.get(id=5)
queryset=VRF.objects.all()
queryset.filter(Q(id=5))
<RestrictedQuerySet [<VRF: Echo (65000:500)>]>
queryset.filter(Q(export_targets__in=echo.import_targets.all()))
<RestrictedQuerySet [<VRF: Shared (65000:1)>]>
queryset.filter(Q(id=5) |Q(export_targets__in=echo.import_targets.all()))
<RestrictedQuerySet [<VRF: Echo (65000:500)>, <VRF: Echo (65000:500)>, <VRF: Shared (65000:1)>]>

I found a kind of explanation on stackoverflow : https://stackoverflow.com/questions/4411049/how-can-i-find-the-union-of-two-django-querysets

Would the .distinct() method answer my issue?

Metadata

Metadata

Assignees

Labels

severity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: 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