fix(schema): leave number pool ranges unset in the write model when they are not declared
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,
rangesislist[NumberPoolRangeWrite] | Noneand defaults toNone. A schema that does not declare the ranges dumps without them; an explicitranges: []stays in the dump. - The read model is unchanged.
write.pyis generated byinvoke backend.generatein 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_absentnow asserts thatrangesis absent from the dump; it fails with the previous write model.- New
test_number_pool_explicit_empty_ranges_survive_the_dumps: an explicitranges: []stays in the server-side dump (exclude_none) and inSchemaRoot.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.loadwith a NumberPool attribute declared withparameters: {}: the pool keeps its ranges. Withranges: []: the pool ends with zero ranges.- Schema built with
SchemaRoot.model_validate(...).to_schema_dict(): without ranges,parametershas norangeskey and the load keeps the ranges; withranges=[],parametersis{"ranges": []}and the load removes them. infrahubctl schema loadon 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.