Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
valentinesd opened this issue Jul 19, 2024 · 2 comments · Fixed by #17015
Closed

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

valentinesd opened this issue Jul 19, 2024 · 2 comments · Fixed by #17015
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation topic: GraphQL type: bug A confirmed report of unexpected behavior in the application

Comments

@valentinesd
Copy link

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

@valentinesd valentinesd added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Jul 19, 2024
@jeremystretch
Copy link
Member

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 jeremystretch removed their assignment Jul 25, 2024
@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: medium Results in substantial degraded or broken functionality for specfic workflows topic: GraphQL and removed status: needs triage This issue is awaiting triage by a maintainer labels Jul 25, 2024
@arthanson
Copy link
Collaborator

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 arthanson self-assigned this Jul 29, 2024
@arthanson arthanson added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Jul 29, 2024
@jeremystretch jeremystretch changed the title In GraphQL when filtering a [object]_list query by [another object]_id filter, if the id doesn't exist all objects are returned GraphQL API returns all object if given filter is invalid Aug 26, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation topic: GraphQL type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants