Problem with filters if filter value is Null

See original GitHub issue

Netbox - v3.1.6 pynetbox - 6.5.0 Repeatability I think on all versions. Let’s look at the request: https://demo.netbox.dev/api/dcim/racks/?site_id=21&location_id=null We’ll get racks with no location. If we try to do the same through the pynetbox library: pynb.dcim.racks.filter(site_id=21, location_id=None) Then we get all the racks on this site. The request will look like: https://demo.netbox.dev/api/dcim/racks/?site_id=21 This applies to both the get request and all objects.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
markkuleiniocommented, Feb 3, 2022

I don’t get why the error says about vrf while your .get() is using vrf_id.

What does your vrf variable contain?

Anyway, this is how it looks like here (pynetbox ~6.5.0, NetBox 3.2.0-dev):

>>> netbox.ipam.prefixes.get(prefix="10.1.1.0/24").vrf is None
True

>>> netbox.ipam.prefixes.get(prefix="10.2.2.0/24").vrf
TestVRF

>>> netbox.ipam.prefixes.get(prefix="10.1.1.0/24", vrf_id="null")
10.1.1.0/24

>>> netbox.ipam.prefixes.get(prefix="10.2.2.0/24", vrf_id="null")
(not found, correct)
0reactions
zachmoodycommented, Feb 6, 2022

@zachmoody what do you think, could we change Request._make_call() to check for any None values and just replace them with "null"? Extra mention in release notes is probably needed.

I don’t know, I agree it is cleaner, but I also worry it could result in some astonishing behavior for clients. E.g. someone initializing a variable that winds up getting passed to get or filter as None now has very confusing result. I think the current behavior with null is worth calling out in the docs though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter by null or missing attributes - Algolia
Generally speaking, selective filtering becomes a problem when the existence or non-existence of a filter value actually means something. The ...
Read more >
Filter on null, blank, or empty values | ThoughtSpot Software
Filtering on NULL and empty values is a special case, and can be tricky if your data contains more than one of these....
Read more >
Filter Query ne null doesnt work - Power Platform Community
I had a test on my side, and Filter Query is not valid for filtering null values. You could use Filter array to...
Read more >
Bug: Filtering on Null Values - Domo Dojo
We do a lot of "not in" filtering... and when you do that, it not only excludes the records with the value you...
Read more >
Javascript Filtering on Null Values - Stack Overflow
Would adding a null check to all of your filters work? So if it is null you return true because you want all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found