Sub filters on GraphQL broken for some queries #9399

Closed
opened 2025-12-29 20:49:19 +01:00 by adam · 0 comments
Owner

Originally created by @arthanson on GitHub (Mar 27, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.0.0

Python Version

3.8

Steps to Reproduce

Found while updating the GraphQL docs for Strawberry. When the sub-field is defined as a function the filtering logic is not applied to it and therefore filtering logic won't work. For example the following query with sub-filter doesn't work:

{
  device_list {
    id
    name
    interfaces(filters: {enabled: {exact: true}}) {
      name
    }
  }
}

This is because it is defined as a function:

    @strawberry_django.field
    def interfaces(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]:
        return self.interfaces.all()

If it is defined as a line type the filtering does work, but this will not work for fields that have to be defined as functions because the accessor is different:

    interfaces: List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]

Adding the filters directly to the decorator does not work either:

    @strawberry_django.field(filters=InterfaceFilter)

Expected Behavior

Filtering should work on all sub-objects

Observed Behavior

Filtering does not work on sub sub-objects.

Originally created by @arthanson on GitHub (Mar 27, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.0.0 ### Python Version 3.8 ### Steps to Reproduce Found while updating the GraphQL docs for Strawberry. When the sub-field is defined as a function the filtering logic is not applied to it and therefore filtering logic won't work. For example the following query with sub-filter doesn't work: ``` { device_list { id name interfaces(filters: {enabled: {exact: true}}) { name } } } ``` This is because it is defined as a function: ``` @strawberry_django.field def interfaces(self) -> List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]: return self.interfaces.all() ``` If it is defined as a line type the filtering does work, but this will not work for fields that have to be defined as functions because the accessor is different: ``` interfaces: List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]] ``` Adding the filters directly to the decorator does not work either: ``` @strawberry_django.field(filters=InterfaceFilter) ``` ### Expected Behavior Filtering should work on all sub-objects ### Observed Behavior Filtering does not work on sub sub-objects.
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 20:49:19 +01:00
adam closed this issue 2025-12-29 20:49:19 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9399