Unable to filter for Prefixes with no VRF set via API #8877

Closed
opened 2025-12-29 20:42:26 +01:00 by adam · 2 comments
Owner

Originally created by @jwbensley on GitHub (Nov 23, 2023).

NetBox version

v3.5.9

Python version

3.10

Steps to Reproduce

  1. I have a VRF created called "DFZ"
  2. I have created a prefix and assigned it to this VRF: 94.103.180.0/26
  3. I have created another prefix which has no VRF assigned: 94.103.180.64/26
  4. I am unable to get the prefix with no VRF set via the API.

I see in this old issue, a search for vrf=null can't be used, but vrf_id=null should work but, neither work for me.

What ever I do, all IPv4 prefixes are returned:

>>> vrf_prefix = list(nb.ipam.prefixes.filter(prefix="94.103.180.0/26"))[0]
>>> vrf_prefix.vrf
DFZ
>>> vrf_prefix.id
3
>>> no_vrf_prefix = list(nb.ipam.prefixes.filter(prefix="94.103.180.64/26"))[0]
>>> no_vrf_prefix.vrf
>>> 
>>> no_vrf_prefix.id
32
>>>
>>>
>>> list(nb.ipam.prefixes.filter(family=4,vrf_id=None))
[94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31]
>>> list(nb.ipam.prefixes.filter(family=4,vrf=None))
[94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31]
>>> list(nb.ipam.prefixes.filter(family=4,vrf_id__n=None))
[94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31]
>>> list(nb.ipam.prefixes.filter(family=4,vrf__n=None))
[94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31]
>>> list(nb.ipam.prefixes.filter(family=4,present_in_vrf=None))
[94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31]
>>> list(nb.ipam.prefixes.filter(family=4,present_in_vrf_id=None))
[94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31]
>>>

Expected Behavior

I think vrf_id__n==None should be the one which returns prefixes with no VRF assigned.

Observed Behavior

All prefixes are always returned, with and without a VRF set.

Originally created by @jwbensley on GitHub (Nov 23, 2023). ### NetBox version v3.5.9 ### Python version 3.10 ### Steps to Reproduce 1. I have a VRF created called "DFZ" 2. I have created a prefix and assigned it to this VRF: `94.103.180.0/26` 3. I have created another prefix which has no VRF assigned: `94.103.180.64/26` 4. I am unable to get the prefix with no VRF set via the API. I see in [this old issue](https://github.com/netbox-community/netbox/issues/3372), a search for `vrf=null` can't be used, but `vrf_id=null` should work but, neither work for me. What ever I do, all IPv4 prefixes are returned: ```python3 >>> vrf_prefix = list(nb.ipam.prefixes.filter(prefix="94.103.180.0/26"))[0] >>> vrf_prefix.vrf DFZ >>> vrf_prefix.id 3 >>> no_vrf_prefix = list(nb.ipam.prefixes.filter(prefix="94.103.180.64/26"))[0] >>> no_vrf_prefix.vrf >>> >>> no_vrf_prefix.id 32 >>> >>> >>> list(nb.ipam.prefixes.filter(family=4,vrf_id=None)) [94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31] >>> list(nb.ipam.prefixes.filter(family=4,vrf=None)) [94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31] >>> list(nb.ipam.prefixes.filter(family=4,vrf_id__n=None)) [94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31] >>> list(nb.ipam.prefixes.filter(family=4,vrf__n=None)) [94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31] >>> list(nb.ipam.prefixes.filter(family=4,present_in_vrf=None)) [94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31] >>> list(nb.ipam.prefixes.filter(family=4,present_in_vrf_id=None)) [94.103.180.64/26, 94.103.180.0/26, 94.103.180.0/31, 94.103.180.2/31, 94.103.180.4/31, 94.103.180.6/31] >>> ``` ### Expected Behavior I think `vrf_id__n==None` should be the one which returns prefixes with no VRF assigned. ### Observed Behavior All prefixes are always returned, with and without a VRF set.
adam closed this issue 2025-12-29 20:42:26 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 27, 2023):

This repo is for the NetBox application. For concerns regarding the pynetbox API client, please raise issues against that repo.

(FYI filtering the prefixes list by ?vrf_id=null does indeed work.)

@jeremystretch commented on GitHub (Nov 27, 2023): This repo is for the NetBox application. For concerns regarding the pynetbox API client, please raise issues against [that repo](https://github.com/netbox-community/pynetbox). (FYI filtering the prefixes list by `?vrf_id=null` does indeed work.)
Author
Owner

@jwbensley commented on GitHub (Nov 27, 2023):

I didn't realise this was a problem with PyNetBox specifically - thanks for clarifying and sorry for the noise.

@jwbensley commented on GitHub (Nov 27, 2023): I didn't realise this was a problem with PyNetBox specifically - thanks for clarifying and sorry for the noise.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8877