[PR #20514] [MERGED] Fixes #20497: Add range_contains lookup and fix VLANGroup VID range filtering #15949

Closed
opened 2025-12-30 00:24:57 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20514
Author: @pheus
Created: 10/6/2025
Status: Merged
Merged: 10/8/2025
Merged by: @jeremystretch

Base: mainHead: 20497-add-arrayfield-rangefield-lookup


📝 Commits (1)

  • 5b6c6e1 feat(extras): Add range_contains ORM lookup

📊 Changes

6 files changed (+134 additions, -19 deletions)

View changed files

📝 netbox/extras/lookups.py (+32 -1)
📝 netbox/ipam/filtersets.py (+2 -16)
📝 netbox/ipam/graphql/filters.py (+2 -2)
📝 netbox/ipam/tests/test_filtersets.py (+4 -0)
netbox/ipam/tests/test_lookups.py (+66 -0)
📝 netbox/netbox/graphql/filter_lookups.py (+28 -0)

📄 Description

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).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20514 **Author:** [@pheus](https://github.com/pheus) **Created:** 10/6/2025 **Status:** ✅ Merged **Merged:** 10/8/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `main` ← **Head:** `20497-add-arrayfield-rangefield-lookup` --- ### 📝 Commits (1) - [`5b6c6e1`](https://github.com/netbox-community/netbox/commit/5b6c6e1dc9b8b9174259f0aa14dfbfb5bae758dc) feat(extras): Add range_contains ORM lookup ### 📊 Changes **6 files changed** (+134 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `netbox/extras/lookups.py` (+32 -1) 📝 `netbox/ipam/filtersets.py` (+2 -16) 📝 `netbox/ipam/graphql/filters.py` (+2 -2) 📝 `netbox/ipam/tests/test_filtersets.py` (+4 -0) ➕ `netbox/ipam/tests/test_lookups.py` (+66 -0) 📝 `netbox/netbox/graphql/filter_lookups.py` (+28 -0) </details> ### 📄 Description ### 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:24:57 +01:00
adam closed this issue 2025-12-30 00:24:58 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15949