Fixes #20497: Add range_contains lookup and fix VLANGroup VID range filtering #1118

Closed
opened 2026-04-05 20:49:52 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 10/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).
*Originally created by @pheus on 10/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).
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#1118