API filter for string custom fields doesn't work properly #11397

Open
opened 2025-12-29 21:44:38 +01:00 by adam · 2 comments
Owner

Originally created by @llamafilm on GitHub (Jul 19, 2025).

Deployment Type

Self-hosted

NetBox Version

v4.3.2

Python Version

3.12

Steps to Reproduce

  1. Create a string type custom field called FWversion.
  2. Set this value to 1 on one device, and 10 for another device.
  3. Filter using dcim/devices/?cf_FWversion=1

Expected Behavior

It should return only the device with exactly matching value, according to the documentation:

To filter results by a custom field value, prepend cf_ to the custom field name. For example, the following query will return only sites where a custom field named foo is equal to 123:
GET /api/dcim/sites/?cf_foo=123

Observed Behavior

It returns both devices. I believe it returns all devices where that field contains the value instead of an exact match.

Originally created by @llamafilm on GitHub (Jul 19, 2025). ### Deployment Type Self-hosted ### NetBox Version v4.3.2 ### Python Version 3.12 ### Steps to Reproduce 1. Create a string type custom field called `FWversion`. 2. Set this value to `1` on one device, and `10` for another device. 3. Filter using `dcim/devices/?cf_FWversion=1` ### Expected Behavior It should return only the device with exactly matching value, according to the documentation: > To filter results by a custom field value, prepend cf_ to the custom field name. For example, the following query will return only sites where a custom field named foo is equal to 123: > `GET /api/dcim/sites/?cf_foo=123` ### Observed Behavior It returns both devices. I believe it returns all devices where that field _contains_ the value instead of an exact match.
adam added the type: bugstatus: under reviewnetboxseverity: low labels 2025-12-29 21:44:38 +01:00
Author
Owner

@llamafilm commented on GitHub (Aug 8, 2025):

Actually, I don't think this is a bug. If I set the custom field to exact filter logic, then the cf_FWversion=1 filter works as expected, the same as cf_FWversion__ie=1.

If the custom field is set to loose filter logic, then cf_FWversion=1 matches both 1 and 10, which is correct according to the docs. But this way, none of the filter expressions work; ie, ic, n, empty, and iew all return the same results.

I'm curious what is the purpose of loose filter logic, since you can achieve the same thing by using the ic expression on a strict field?

@llamafilm commented on GitHub (Aug 8, 2025): Actually, I don't think this is a bug. If I set the custom field to `exact` filter logic, then the `cf_FWversion=1` filter works as expected, the same as `cf_FWversion__ie=1`. If the custom field is set to `loose` filter logic, then `cf_FWversion=1` matches both 1 and 10, which is correct according to the [docs](https://netboxlabs.com/docs/netbox/reference/filtering/). But this way, none of the filter expressions work; `ie`, `ic`, `n`, `empty`, and `iew` all return the same results. I'm curious what is the purpose of `loose` filter logic, since you can achieve the same thing by using the `ic` expression on a strict field?
Author
Owner

@jnovinger commented on GitHub (Oct 21, 2025):

I think the behavior described in the original report is intended behavior.

If the custom field is set to loose filter logic, then cf_FWversion=1 matches both 1 and 10, which is correct according to the docs. But this way, none of the filter expressions work; ie, ic, n, empty, and iew all return the same results.

However, I don't know if this is intended behavior. I'll discuss this with the other maintainers.

@jnovinger commented on GitHub (Oct 21, 2025): I think the behavior described in the original report is intended behavior. > If the custom field is set to loose filter logic, then cf_FWversion=1 matches both 1 and 10, which is correct according to the [docs](https://netboxlabs.com/docs/netbox/reference/filtering/). But this way, none of the filter expressions work; ie, ic, n, empty, and iew all return the same results. However, I don't know if this is intended behavior. I'll discuss this with the other maintainers.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11397