-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Open
Open
Copy link
Labels
severity: lowDoes not significantly disrupt application functionality, or a workaround is availableDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application
Description
NetBox Edition
NetBox Community
NetBox Version
v4.4.2
Python Version
3.12
Steps to Reproduce
- Run a nested GraphQL query that relies on a custom filter method returning a raw
Q(...)
without applying the Strawberry‑Djangoprefix
(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 } } }
- 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 anyreturn Q(...)
to includeprefix
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 incorporateprefix
.
References
- Example bug & reproduction: Unable to query devices with primary-ip set in GraphQL - "Cannot resolve keyword 'assigned_object_id' into field" #20466
- Strawberry‑Django docs show
prefix
is required for nested filters and demonstrate qualifiedQ(**{f"{prefix}…": …})
lookups.
Metadata
Metadata
Assignees
Labels
severity: lowDoes not significantly disrupt application functionality, or a workaround is availableDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the applicationA confirmed report of unexpected behavior in the application