API GET /api/dcim/devices with site and site__n not working properly #9239

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

Originally created by @jayGG83 on GitHub (Feb 13, 2024).

Deployment Type

netbox-docker

NetBox Version

v3.7.1

Python Version

3.10

Steps to Reproduce

  1. Create a Site
  2. Create a device type
  3. Create a device and assign to the site
  4. Execute /api/dcim/devices/?site={site_name}
  5. Execute /api/dcim/devices/?site={site_slug}
  6. Execute /api/dcim/devices/?site__n={site_slug}

Expected Behavior

Expected behavior
Step 4: Return the information regarding the devices in site based on the site name
Step 5: It should return an error stating that the site value provided is not one of the available choices, as we provided the slug name instead of the site name
Step 6: Return the information regarding the devices in site based on the slug name

Observed Behavior

Step 4: Returned:

{
  "site": [
    "Select a valid choice. {site_name} is not one of the available choices."
  ]
}

Step 5: Returned a valid result. Attribute site accepts the slug name instead of the site name.
Step 6: Returned all existing devices from all sites

Originally created by @jayGG83 on GitHub (Feb 13, 2024). ### Deployment Type netbox-docker ### NetBox Version v3.7.1 ### Python Version 3.10 ### Steps to Reproduce 1. Create a Site 2. Create a device type 3. Create a device and assign to the site 4. Execute ```/api/dcim/devices/?site={site_name}``` 5. Execute ```/api/dcim/devices/?site={site_slug}``` 6. Execute ```/api/dcim/devices/?site__n={site_slug}``` ### Expected Behavior Expected behavior Step 4: Return the information regarding the devices in site based on the site name Step 5: It should return an error stating that the site value provided is not one of the available choices, as we provided the slug name instead of the site name Step 6: Return the information regarding the devices in site based on the slug name ### Observed Behavior Step 4: Returned: ```json { "site": [ "Select a valid choice. {site_name} is not one of the available choices." ] } ``` Step 5: Returned a valid result. Attribute site accepts the slug name instead of the site name. Step 6: Returned all existing devices from all sites
adam closed this issue 2025-12-29 20:47:23 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 13, 2024):

These filters are working as expected.

  • ?site={site_name} is not a valid query, as the site filter matches against the slug, not the name
  • ?site={site_slug} works as expected, returning only the devices assigned to the specified site
  • ?site__n={site_slug} works as expected, returning only the devices not assigned to the specified site
@jeremystretch commented on GitHub (Feb 13, 2024): These filters are working as expected. * `?site={site_name}` is not a valid query, as the `site` filter matches against the slug, not the name * `?site={site_slug}` works as expected, returning only the devices assigned to the specified site * `?site__n={site_slug}` works as expected, returning only the devices _not_ assigned to the specified site
Author
Owner

@jayGG83 commented on GitHub (Feb 13, 2024):

Thanks for the info. Now I see the pattern that I didn't saw before. So any attribute with __n means not in?

@jayGG83 commented on GitHub (Feb 13, 2024): Thanks for the info. Now I see the pattern that I didn't saw before. So any attribute with __n means not in?
Author
Owner

@jeremystretch commented on GitHub (Feb 13, 2024):

Yeah, the n is a lookup modifier which negates the query. It works similarly to __gt (greater than) and __lt (less than) for numeric fields.

@jeremystretch commented on GitHub (Feb 13, 2024): Yeah, the `n` is a lookup modifier which negates the query. It works similarly to `__gt` (greater than) and `__lt` (less than) for numeric fields.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9239