Fixes #20541: Enhance GraphQL filter methods with dynamic prefixing #20579
+250
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #20541
Refactors filter methods to enable dynamic query prefixing for greater flexibility in nested queries. Improves error handling for invalid network inputs and ensures consistency across IPAM filter implementations.
Context
This follows the discussion in Bug #20466 and builds on PR #20538 (which addressed
IPAddressFilter.assigned). The goal here is to complete the prefixing/validation sweep withinipam.graphql.filtersonly and ensure nested filters consistently target the correct related model.Summary of changes
Standardize construction of lookups as
Q(**{f"{prefix}…": …})in custom filter methods so nested queries are resolved against the intended model path.contains/parent-style helpers now guard network parsing withtry/except, skipping invalid entries rather than failing the entire filter.Minor internal tidy-ups (e.g., shared helper for device-based lookups) while preserving existing behavior.
🚨 Breaking change (GraphQL):
AggregateFilterAggregate.prefixis a concrete field, not a relation. To avoid double-qualifying lookups in nested contexts, this PR proposes:contains(value: [CIDR])that appliesprefix__net_containsto the Aggregate field itself.Client impact (input shape changed for Aggregates only):
No other GraphQL inputs are changed.
Files/areas touched (IPAM only)
ipam.graphql.filters.AggregateFilterprefixnow aFilterLookup[str]on the field.contains([...])usesprefix__net_contains.ipam.graphql.filters.PrefixFiltercontains([...])remains relation-aware; lookups are prefixed viaf"{prefix}prefix__net_contains".ipam.graphql.filters.IPRangeFilterparent([...])andcontains([...])use prefixed lookups with input validation.ipam.graphql.filters.IPAddressFilterparent([...])uses prefixed lookups with input validation.assignedwas handled in PR Fixes #20466: Correct handling ofassignedfilter logic #20538 per Bug Unable to query devices with primary-ip set in GraphQL - "Cannot resolve keyword 'assigned_object_id' into field" #20466.)Upgrade notes
aggregate_list(filters: { contains: ["<cidr>"] })for containment, andaggregate_list(filters: { prefix: { exact: "<cidr>" } })for equality.Related
assignedfilter logic #20538