Being able to filter on whether a field is empty or null #4747

Closed
opened 2025-12-29 19:20:05 +01:00 by adam · 3 comments
Owner

Originally created by @OtherSystems on GitHub (Apr 11, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v2.10.8

Feature type

Change to existing functionality

Proposed functionality

Similar to #4522

Would like to be filter on fields (such as dns_name) to empty or not empty, so get a list of where dns_name is not set or just has anything

Perhaps this could be done with the filter dns_name__null or dns_name__empty and for the reverse dns_name__notempty or dns_name__notnull

For us the syntax wouldn't matter, as long as the functionality is possible.

Use case

we have scripts that operate on dns_name currently we check this with dns_name_ic=. to see if there any to use but that's a bit ugly and not 100% correct.

Checking for empty fields would also be useful for scripts where you want to inform users/admins of incomplete entries, like where someone has forgotten to set the platform or location of a device.

Database changes

No response

External dependencies

No response

Originally created by @OtherSystems on GitHub (Apr 11, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v2.10.8 ### Feature type Change to existing functionality ### Proposed functionality Similar to #4522 Would like to be filter on fields (such as dns_name) to empty or not empty, so get a list of where dns_name is not set or just has anything Perhaps this could be done with the filter dns_name__null or dns_name__empty and for the reverse dns_name__notempty or dns_name__notnull For us the syntax wouldn't matter, as long as the functionality is possible. ### Use case we have scripts that operate on dns_name currently we check this with dns_name_ic=. to see if there any to use but that's a bit ugly and not 100% correct. Checking for empty fields would also be useful for scripts where you want to inform users/admins of incomplete entries, like where someone has forgotten to set the platform or location of a device. ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 19:20:05 +01:00
adam closed this issue 2025-12-29 19:20:05 +01:00
Author
Owner

@nahun commented on GitHub (Apr 14, 2021):

I'll add another specific use case for this feature:

I use the dns_name field in NetBox to populate DNS records with a webhook. But since users can still mess with the DNS records outside of netbox, I run an "audit" script daily that takes the data in netbox and updates the DNS records if there were any changes done outside of netbox that conflicts. To do this I pull down all the IP addresses and then filter those with a dns_name set in the code. The query would be much quicker if I could filter IP addresses with a non-null or non-empty dns_name.

@nahun commented on GitHub (Apr 14, 2021): I'll add another specific use case for this feature: I use the `dns_name` field in NetBox to populate DNS records with a webhook. But since users can still mess with the DNS records outside of netbox, I run an "audit" script daily that takes the data in netbox and updates the DNS records if there were any changes done outside of netbox that conflicts. To do this I pull down all the IP addresses and then filter those with a dns_name set in the code. The query would be **much** quicker if I could filter IP addresses with a non-null or non-empty dns_name.
Author
Owner

@devon-mar commented on GitHub (May 6, 2021):

Filtering by null fields currently works by using null as the value (#2632) but the ability to filter by not null is currently not available.

I tried using dns_name__n=null but it doesn't seem to work due to the current implementation.

@devon-mar commented on GitHub (May 6, 2021): Filtering by null fields currently works by using `null` as the value (#2632) but the ability to filter by not null is currently not available. I tried using `dns_name__n=null` but it doesn't seem to work due to the [current implementation](https://github.com/netbox-community/netbox/blob/b93570eeb07a3390f4f6dd32f845cc3c3fb533f2/netbox/utilities/filters.py#L82).
Author
Owner

@jeremystretch commented on GitHub (Jul 1, 2021):

I've added a custom empty lookup to address this use case. You can now do e.g. ?dns_name__empty=False to return all records with non-empty values.

@jeremystretch commented on GitHub (Jul 1, 2021): I've added a custom `empty` lookup to address this use case. You can now do e.g. `?dns_name__empty=False` to return all records with non-empty values.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4747