"Platform" field doesn't fully support lookup expression #3746

Closed
opened 2025-12-29 18:30:53 +01:00 by adam · 1 comment
Owner

Originally created by @eshcheglov on GitHub (Jun 3, 2020).

Environment

  • Python version: 3.6.8
  • NetBox version: 2.8.5

Steps to Reproduce

  1. Create Platform with any name. e.x: name: "Windows Server", slug:"windows-server"
  2. Create device and set it platform to "Windows Server"
  3. Try to apply "nic" lookup expression (__nic) to "platform" field:
GET /api/dcim/devices/?limit=0platform__nic=Windows

HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "count": 1

However, regular "n" expression (__n) can be applied:

GET /api/dcim/devices/?limit=0&platform__n=windows-server

HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "count": 0

Expected Behavior

Devices with "Windows" in "Platform" parameter filtered out

Observed Behavior

Devices with "Windows" in "Platform" parameter is still visible

Originally created by @eshcheglov on GitHub (Jun 3, 2020). ### Environment * Python version: 3.6.8 * NetBox version: 2.8.5 ### Steps to Reproduce 1. Create Platform with any name. e.x: name: "Windows Server", slug:"windows-server" 2. Create device and set it platform to "Windows Server" 3. Try to apply **"nic"** lookup expression (__nic) to "platform" field: ``` GET /api/dcim/devices/?limit=0platform__nic=Windows HTTP 200 OK Allow: GET, POST, HEAD, OPTIONS Content-Type: application/json Vary: Accept { "count": 1 ``` However, regular "**n**" expression (__n) can be applied: ``` GET /api/dcim/devices/?limit=0&platform__n=windows-server HTTP 200 OK Allow: GET, POST, HEAD, OPTIONS Content-Type: application/json Vary: Accept { "count": 0 ``` ### Expected Behavior Devices with "Windows" in "Platform" parameter filtered out ### Observed Behavior Devices with "Windows" in "Platform" parameter is still visible
adam closed this issue 2025-12-29 18:30:53 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jun 3, 2020):

Per the docs:

Certain other fields, namely foreign key relationships support just the negation expression: n

platform is a ForeignKey field, from the Device model to the Platform model, as opposed to a CharField on the Device model. Thus, only basic negation is supported.

@jeremystretch commented on GitHub (Jun 3, 2020): Per [the docs](https://netbox.readthedocs.io/en/stable/api/filtering/): > Certain other fields, namely foreign key relationships support just the negation expression: n `platform` is a ForeignKey field, from the Device model to the Platform model, as opposed to a CharField on the Device model. Thus, only basic negation is supported.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3746