fix(schema): leave number pool ranges unset in the write model when they are not declared

Merged
PO
3d ago
+17-5

Why

NumberPoolParametersWrite.ranges defaulted to an empty list, so a schema that leaves the ranges out of a NumberPool attribute's parameters dumped the same as one that declares ranges: []. The Infrahub server builds its internal schema from that dump, and could not tell "keep the stored ranges" from "remove every range".

Jira: IFC-3412

What changed

  • In the write model, ranges is list[NumberPoolRangeWrite] | None and defaults to None. A schema that does not declare the ranges dumps without them; an explicit ranges: [] stays in the dump.
  • The read model is unchanged.
  • write.py is generated by invoke backend.generate in the Infrahub repository; the generator change and the submodule bump are in the companion Infrahub pull request.

Related to https://github.com/opsmill/infrahub/pull/11089

How to review

Read the ranges field in infrahub_sdk/schema/generated/write.py, then the two tests in tests/unit/test_schema_offline_validation.py.

Tests

  • test_number_pool_without_any_range_spelling_leaves_the_range_fields_absent now asserts that ranges is absent from the dump; it fails with the previous write model.
  • New test_number_pool_explicit_empty_ranges_survive_the_dumps: an explicit ranges: [] stays in the server-side dump (exclude_none) and in SchemaRoot.to_schema_dict().

Tests against the live application

Run with this branch installed as the SDK of a local Infrahub stack running opsmill/infrahub#11089:

  • client.schema.load with a NumberPool attribute declared with parameters: {}: the pool keeps its ranges. With ranges: []: the pool ends with zero ranges.
  • Schema built with SchemaRoot.model_validate(...).to_schema_dict(): without ranges, parameters has no ranges key and the load keeps the ranges; with ranges=[], parameters is {"ranges": []} and the load removes them.
  • infrahubctl schema load on a directory of two YAML files: parameters: {} keeps the ranges, ranges: [] removes them.

🤖 Generated with Claude Code


Summary by cubic

Makes the schema write model distinguish a NumberPool attribute that leaves its ranges undeclared from one that explicitly declares ranges: []. Previously both dumped the same empty list, so a schema reload could not tell "keep the stored ranges" from "remove every range" (IFC-3412). NumberPoolParametersWrite.ranges now defaults to None and is omitted from dumps when unset, while an explicit empty list is preserved.