filter present_in_vrf_id returning more results than expected #10183

Closed
opened 2025-12-29 21:27:55 +01:00 by adam · 5 comments
Owner

Originally created by @pl0xym0r on GitHub (Sep 4, 2024).

Originally assigned to: @pl0xym0r on GitHub.

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 : 886d635524/netbox/ipam/filtersets.py (L455)

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?

Originally created by @pl0xym0r on GitHub (Sep 4, 2024). Originally assigned to: @pl0xym0r on GitHub. ### 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 : https://github.com/netbox-community/netbox/blob/886d6355243b8ebe460b097228a9d5c36aebe0f8/netbox/ipam/filtersets.py#L455 ![image](https://github.com/user-attachments/assets/0f71629e-1a88-4319-91e6-e3ac8a915e62) 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?
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:27:55 +01:00
adam closed this issue 2025-12-29 21:27:55 +01:00
Author
Owner

@arthanson commented on GitHub (Sep 4, 2024):

@pl0xym0r Can you please expand on your reproduction steps - where is "VRF shared", can you please detail which menu item you are going to, also I'm not seeing where you are getting Shared and Echo from.

@arthanson commented on GitHub (Sep 4, 2024): @pl0xym0r Can you please expand on your reproduction steps - where is "VRF shared", can you please detail which menu item you are going to, also I'm not seeing where you are getting Shared and Echo from.
Author
Owner

@pl0xym0r commented on GitHub (Sep 4, 2024):

All the data come from the demo-data

Even netbox demo has the issue:
1 go to prefix
2 filter : present_in_vrf select echo
image

Filter on delta VRF, same behavior:
image

All prefixes in VRF selected are shown twice (not expected), from VRF RT imported once as expected

@pl0xym0r commented on GitHub (Sep 4, 2024): All the data come from the demo-data Even netbox demo has the issue: 1 go to prefix 2 filter : present_in_vrf select echo ![image](https://github.com/user-attachments/assets/acca4a4f-e885-408a-906d-15bf59451616) Filter on delta VRF, same behavior: ![image](https://github.com/user-attachments/assets/affe966b-7115-41c5-b979-b8502a2cfc95) All prefixes in VRF selected are shown twice (not expected), from VRF RT imported once as expected
Author
Owner

@pl0xym0r commented on GitHub (Sep 4, 2024):

if needed, I can update the functions. Idk if the same behavior is on IPAddressFilterSet as the same function exists. I'd like to update both

@pl0xym0r commented on GitHub (Sep 4, 2024): if needed, I can update the functions. Idk if the same behavior is on IPAddressFilterSet as the same function exists. I'd like to update both
Author
Owner

@arthanson commented on GitHub (Sep 4, 2024):

@pl0xym0r I'll assign to you then.

@arthanson commented on GitHub (Sep 4, 2024): @pl0xym0r I'll assign to you then.
Author
Owner

@pl0xym0r commented on GitHub (Sep 4, 2024):

same issue for ip-addresses:
image

@pl0xym0r commented on GitHub (Sep 4, 2024): same issue for ip-addresses: ![image](https://github.com/user-attachments/assets/abfc5803-6d30-49b5-ad5e-92e74a3945f1)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10183