Skip to content

Conversation

@pheus
Copy link
Contributor

@pheus pheus commented Oct 6, 2025

Fixes: #20497

Summary
Introduce a generic ORM lookup range_contains for ArrayField(RangeField) to correctly match rows where a scalar value is contained by any range in the array (e.g., VLANGroup.vid_ranges). This replaces the raw‑SQL helper used by the VLAN group filter and aligns REST and GraphQL semantics with PostgreSQL range operators.

Changes

  • extras: Add and register the range_contains lookup (guarded to ArrayField(RangeField)).
  • ipam/filtersets: Refactor VLANGroup FilterSet (contains_vid) to use the lookup (remove raw SQL).
  • GraphQL schema:
    • Add an IntegerRangeArrayLookup input and wire VLANGroup.vid_ranges to it.
    • Keep the public API friendly: clients use vid_ranges: { contains: <Int> }, which maps internally to __range_contains.

Tests

  • Add ORM unit tests for the lookup (positive, negative, and boundary cases).
  • Add REST FilterSet tests for ?contains_vid=<int> (hit/miss and exclusive upper bound).

@pheus
Copy link
Contributor Author

pheus commented Oct 6, 2025

Naming note: I used any_range_contains for the lookup (ArrayField(RangeField) → “value is contained by any range”). If the team prefers a different name (e.g., in_any_range), I’m happy to rename it and update tests, the REST FilterSet, and the GraphQL mapping accordingly.

@jnovinger jnovinger requested review from a team and jeremystretch and removed request for a team October 6, 2025 15:06
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @pheus! Just had a couple minor suggestions.

@pheus pheus force-pushed the 20497-add-arrayfield-rangefield-lookup branch from dea6408 to d68f0ab Compare October 8, 2025 10:55
@pheus pheus changed the title Fixes #20497: Add any_range_contains lookup and fix VLANGroup VID range filtering Fixes #20497: Add range_contains lookup and fix VLANGroup VID range filtering Oct 8, 2025
@pheus pheus force-pushed the 20497-add-arrayfield-rangefield-lookup branch from d68f0ab to 5b40ff9 Compare October 8, 2025 10:57
Introduce a generic lookup for ArrayField(RangeField) that matches rows
where a scalar value is contained by any range in the array
(e.g. VLANGroup.vid_ranges).
Replace the raw-SQL helper in the VLANGroup FilterSet (`contains_vid`)
with the ORM lookup for better maintainability.
Add tests for the lookup and the FilterSet behavior.

Closes netbox-community#20497
@pheus pheus force-pushed the 20497-add-arrayfield-rangefield-lookup branch from 5b40ff9 to 5b6c6e1 Compare October 8, 2025 11:01
@pheus pheus requested a review from jeremystretch October 8, 2025 11:16
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pheus!

@jeremystretch jeremystretch merged commit 33d4759 into netbox-community:main Oct 8, 2025
7 checks passed
@pheus pheus deleted the 20497-add-arrayfield-rangefield-lookup branch October 8, 2025 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filtering VLANGroup by vid_ranges.contains in GraphQL fails with “cannot cast type integer to int4range”

2 participants