Add REST API filtering support for dcim.devices Serial field #6647

Closed
opened 2025-12-29 19:43:29 +01:00 by adam · 2 comments
Owner

Originally created by @decoupca on GitHub (Jul 11, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.1.2

Feature type

Change to existing functionality

Proposed functionality

According to the docs, string fields can be filtered with expressions. However, the serial number field is not, in fact, filterable using any provided expression (except exact match). I propose to include serial number in the list of available fields to filter using expressions. If this FR is not approved, I propose clarifying this exception in the docs.

Use case

I wanted to share a link with my colleagues to a list of all devices that lack a serial number value. Based on the docs, this should be possible by appending ?serial__empty=true to the query string. This is much easier than either exporting a static CSV and filtering it, or going to the trouble of writing a report.

It also may be useful to search for serial numbers beginning or ending with a certain string to identify devices affected by the same OEM issue.

Moreover, since the API filtering logic is already implemented for other fields, it seems sensible and feasible to enable that for serial numbers as well.

Database changes

None, as far as I can tell

External dependencies

None

Originally created by @decoupca on GitHub (Jul 11, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.1.2 ### Feature type Change to existing functionality ### Proposed functionality According to the [docs](https://docs.netbox.dev/en/stable/rest-api/filtering/#string-fields), string fields can be filtered with expressions. However, the serial number field is not, in fact, filterable using any provided expression (except exact match). I propose to include serial number in the list of available fields to filter using expressions. If this FR is not approved, I propose clarifying this exception in the docs. ### Use case I wanted to share a link with my colleagues to a list of all devices that lack a serial number value. Based on the docs, this should be possible by appending `?serial__empty=true` to the query string. This is much easier than either exporting a static CSV and filtering it, or going to the trouble of writing a report. It also may be useful to search for serial numbers beginning or ending with a certain string to identify devices affected by the same OEM issue. Moreover, since the API filtering logic is already implemented for other fields, it seems sensible and feasible to enable that for serial numbers as well. ### Database changes None, as far as I can tell ### External dependencies None
adam added the status: acceptedtype: feature labels 2025-12-29 19:43:29 +01:00
adam closed this issue 2025-12-29 19:43:29 +01:00
Author
Owner

@DanSheps commented on GitHub (Jul 11, 2022):

Just adding on, this might have something to do with the lookup_expr, however I was unable to get __empty to work on any string field from my (admittedly) limited testing

@DanSheps commented on GitHub (Jul 11, 2022): Just adding on, this might have something to do with the lookup_expr, however I was unable to get __empty to work on any string field from my (admittedly) limited testing
Author
Owner

@jeremystretch commented on GitHub (Jul 20, 2022):

The problem here is that we've explicitly defined the serial filter on DeviceFilterSet (I believe this was done prior to the implementation of automated lookup generation). The same issue is present for the serial field on racks and inventory items as well (but on modules).

@jeremystretch commented on GitHub (Jul 20, 2022): The problem here is that we've explicitly defined the `serial` filter on DeviceFilterSet (I believe this was done prior to the implementation of automated lookup generation). The same issue is present for the `serial` field on racks and inventory items as well (but on modules).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6647