Fixes #20491: Normalize numeric range array fields for API test comparisons #745

Closed
opened 2026-04-05 17:25:00 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 12/10/2025

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.

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

No dependencies set.

Reference: github/netbox#745