GraphQL API returns all object if given filter is invalid #9994

Closed
opened 2025-12-29 21:25:23 +01:00 by adam · 2 comments
Owner

Originally created by @valentinesd on GitHub (Jul 19, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0.7

Python Version

3.10

Steps to Reproduce

My specific use case is vlan_list filtered by site id, but the behavior can be observed across all objects (eg site_list filtered by region_id)
Add VLANs to netbox and perform a GraphQL query similar to below (where 1234567890 is not a valid site)

{
  vlan_list(filters: {site_id: "1234567890"}){
    id
    vid
    site {
      id
    }
    tenant {
      id
    }
  }
}

Expected Behavior

Return an empty list or error, as the filter is not satisfied

Observed Behavior

Returns all objects

Originally created by @valentinesd on GitHub (Jul 19, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0.7 ### Python Version 3.10 ### Steps to Reproduce My specific use case is vlan_list filtered by site id, but the behavior can be observed across all objects (eg site_list filtered by region_id) Add VLANs to netbox and perform a GraphQL query similar to below (where 1234567890 is not a valid site) ``` { vlan_list(filters: {site_id: "1234567890"}){ id vid site { id } tenant { id } } } ``` ### Expected Behavior Return an empty list or error, as the filter is not satisfied ### Observed Behavior Returns all objects
adam added the type: bugstatus: acceptedtopic: GraphQLseverity: medium labels 2025-12-29 21:25:23 +01:00
adam closed this issue 2025-12-29 21:25:23 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jul 26, 2024):

This appears to be the same behavior as the web UI: Filtering a list of objects by an invalid foreign key to some other object negates the filter and returns an unfiltered list. (The REST API, however, does return an error.)

@jeremystretch commented on GitHub (Jul 26, 2024): This appears to be the same behavior as the web UI: Filtering a list of objects by an invalid foreign key to some other object negates the filter and returns an unfiltered list. (The REST API, however, does return an error.)
Author
Owner

@arthanson commented on GitHub (Jul 29, 2024):

I think some extra logic would be needed here: https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/graphql/filter_mixins.py#L204 as it is just returning the filterset which is returning all the items, REST must have specific logic to catch this case., will need to be ported here.

@arthanson commented on GitHub (Jul 29, 2024): I think some extra logic would be needed here: https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/graphql/filter_mixins.py#L204 as it is just returning the filterset which is returning all the items, REST must have specific logic to catch this case., will need to be ported here.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9994