NetBoxModelFilterSet causes GraphQL queries on custom-fields even if not referenced #7745

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

Originally created by @arthanson on GitHub (Mar 10, 2023).

NetBox version

v3.4.5

Python version

3.8

Steps to Reproduce

This only appears in GraphQL as you can specify which fields to return, where REST API returns all the fields and has prefetch_related for the custom-fields. Make a graphql call to any model that uses NetBoxModelFilterSet, in the debug toolbar look at the queries and see that queries are made to custom-field even though they aren't referenced in the query. Example query below:

query vlan {
	vlan_list {
                id
	}
}

Traced down the issue: https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/filtersets.py#L249 This code is causing custom-fields to be queried even if they aren't in GraphQL request.

Found while working on issue #11291 so opening a separate bug to track.

Expected Behavior

If custom-fields are not referenced in the filter then then queries shouldn't be done for them.

Observed Behavior

Queries are always added for the custom fields.

Originally created by @arthanson on GitHub (Mar 10, 2023). ### NetBox version v3.4.5 ### Python version 3.8 ### Steps to Reproduce This only appears in GraphQL as you can specify which fields to return, where REST API returns all the fields and has prefetch_related for the custom-fields. Make a graphql call to any model that uses NetBoxModelFilterSet, in the debug toolbar look at the queries and see that queries are made to custom-field even though they aren't referenced in the query. Example query below: ``` query vlan { vlan_list { id } } ``` Traced down the issue: https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/filtersets.py#L249 This code is causing custom-fields to be queried even if they aren't in GraphQL request. Found while working on issue #11291 so opening a separate bug to track. ### Expected Behavior If custom-fields are not referenced in the filter then then queries shouldn't be done for them. ### Observed Behavior Queries are always added for the custom fields.
adam added the type: bugnetboxtopic: GraphQLseverity: low labels 2025-12-29 20:27:45 +01:00
adam closed this issue 2025-12-29 20:27:45 +01:00
Author
Owner

@arthanson commented on GitHub (Apr 21, 2023):

Adding blocked till: #9856

@arthanson commented on GitHub (Apr 21, 2023): Adding blocked till: #9856
Author
Owner

@jeremypng commented on GitHub (Jan 23, 2025):

This is fixed in my branch here:
https://github.com/jeremypng/netbox/tree/refs/heads/graphql-filter-redesign

If you'll assign this to me I'll tag this issue in my PR request.

@jeremypng commented on GitHub (Jan 23, 2025): This is fixed in my branch here: https://github.com/jeremypng/netbox/tree/refs/heads/graphql-filter-redesign If you'll assign this to me I'll tag this issue in my PR request.
Author
Owner

@jeremystretch commented on GitHub (Feb 7, 2025):

Make a graphql call to any model that uses NetBoxModelFilterSet, in the debug toolbar look at the queries and see that queries are made to custom-field even though they aren't referenced in the query.

I'm not able to reproduce this on NetBox v4.2.3. When issuing a query for any model with a custom field to retrieve the list of IDs, only one SQL query is produced. This issue was probably addressed by a more recent Strawberry release or some other change made since it was opened.

@jeremystretch commented on GitHub (Feb 7, 2025): > Make a graphql call to any model that uses NetBoxModelFilterSet, in the debug toolbar look at the queries and see that queries are made to custom-field even though they aren't referenced in the query. I'm not able to reproduce this on NetBox v4.2.3. When issuing a query for any model with a custom field to retrieve the list of IDs, only one SQL query is produced. This issue was probably addressed by a more recent Strawberry release or some other change made since it was opened.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7745