netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.93k stars 2.56k forks source link

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

Open arthanson opened 1 year ago

arthanson commented 1 year ago

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.

arthanson commented 1 year ago

Adding blocked till: #9856