Skip to content

Ensure all custom GraphQL filter methods apply prefix in Q(...) for nested filters #20541

@pheus

Description

@pheus

NetBox Edition

NetBox Community

NetBox Version

v4.4.2

Python Version

3.12

Steps to Reproduce

  1. Run a nested GraphQL query that relies on a custom filter method returning a raw Q(...) without applying the Strawberry‑Django prefix (illustrative example from Unable to query devices with primary-ip set in GraphQL - "Cannot resolve keyword 'assigned_object_id' into field" #20466):
    query {
      device_list(filters: { primary_ip4: { assigned: true } }) {
        id
        primary_ip4 { address }
      }
    }
  2. Observe that the generated lookup key is unqualified (e.g., assigned_object_id__isnull) and is applied to the outer model rather than the nested relation, producing an error like “Cannot resolve keyword ‘assigned_object_id’ into field”.

Note: #20466 proposes/fixes one concrete instance in IPAddressFilter.assigned by using return Q(**{f"{prefix}assigned_object_id__isnull": not value}). This issue tracks auditing other custom filter methods for the same class of bug.

Expected Behavior

All custom GraphQL filter methods that return Q qualify their lookups using the provided prefix, so nested filters target the correct related model and do not error.

Observed Behavior

At least one confirmed case (#20466) shows a custom filter method constructing Q(...) without prefix, causing nested filters to mis-target the outer model and fail with “Cannot resolve keyword …”. Other custom filter methods that build raw Q(...) may be similarly affected.


Proposed Fix / Scope

  • Audit all @strawberry_django.filter_field() methods across GraphQL filters and update any return Q(...) to include prefix in the lookup keys. Example pattern:
    @strawberry_django.filter_field()
    def <name>(self, value: T, prefix: str) -> Q:
        return Q(**{f"{prefix}<field_path>": value})
  • Where a method returns (queryset, Q), ensure any annotated keys or aliases also incorporate prefix.

References

Metadata

Metadata

Assignees

Labels

severity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions