[PR #20963] [MERGED] Fixes #20491: Normalize numeric range array fields for API test comparisons #16103

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20963
Author: @pheus
Created: 12/10/2025
Status: Merged
Merged: 12/16/2025
Merged by: @bctiemann

Base: mainHead: 20491-normalize-arrayfield-values-to-inclusive-pairs-for-api-tests


📝 Commits (1)

  • 60fce84 feat(ipam): Normalize numeric ranges in API output

📊 Changes

2 files changed (+10 additions, -3 deletions)

View changed files

📝 netbox/ipam/tests/test_api.py (+3 -0)
📝 netbox/utilities/testing/base.py (+7 -3)

📄 Description

Fixes: #20491

This PR updates the API testing utilities so that numeric range array fields are represented consistently with the API serializers.

Specifically:

  • In utilities.testing.base.model_to_dict(), when api=True and the field is an ArrayField of a RangeField (e.g. ArrayField(IntegerRangeField)), the values are converted from psycopg's canonical half‑open ranges [low, high) into inclusive [low, high] pairs before comparison.
  • This matches the behavior of IntegerRangeSerializer(many=True, required=False), which exposes ranges as inclusive [low, high] pairs at the API boundary (for example, VLANGroup.vid_ranges).
  • The change is limited to the test harness and does not affect runtime behavior or the public API; it only ensures that APIViewTestCase compares data using the same representation as the serializers.

As a small regression check, the VLAN group API test (VLANGroupTest in ipam.tests.test_api) is updated to include a vid_ranges value in create_data so that this path is exercised automatically going forward.


🔄 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/20963 **Author:** [@pheus](https://github.com/pheus) **Created:** 12/10/2025 **Status:** ✅ Merged **Merged:** 12/16/2025 **Merged by:** [@bctiemann](https://github.com/bctiemann) **Base:** `main` ← **Head:** `20491-normalize-arrayfield-values-to-inclusive-pairs-for-api-tests` --- ### 📝 Commits (1) - [`60fce84`](https://github.com/netbox-community/netbox/commit/60fce84c96e952ba72f00b6e57de259ddf35b766) feat(ipam): Normalize numeric ranges in API output ### 📊 Changes **2 files changed** (+10 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `netbox/ipam/tests/test_api.py` (+3 -0) 📝 `netbox/utilities/testing/base.py` (+7 -3) </details> ### 📄 Description ### Fixes: #20491 This PR updates the API testing utilities so that numeric range array fields are represented consistently with the API serializers. Specifically: - In `utilities.testing.base.model_to_dict()`, when `api=True` and the field is an `ArrayField` of a `RangeField` (e.g. `ArrayField(IntegerRangeField)`), the values are converted from psycopg's canonical half‑open ranges `[low, high)` into inclusive `[low, high]` pairs before comparison. - This matches the behavior of `IntegerRangeSerializer(many=True, required=False)`, which exposes ranges as inclusive `[low, high]` pairs at the API boundary (for example, `VLANGroup.vid_ranges`). - The change is limited to the test harness and does not affect runtime behavior or the public API; it only ensures that `APIViewTestCase` compares data using the same representation as the serializers. As a small regression check, the VLAN group API test (`VLANGroupTest` in `ipam.tests.test_api`) is updated to include a `vid_ranges` value in `create_data` so that this path is exercised automatically going forward. --- <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:25:48 +01:00
adam closed this issue 2025-12-30 00:25:48 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#16103