Skip to content

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

Merged
polmichel merged 1 commit into
infrahub-developfrom
pmi-number-pool-write-ranges-unset-ifc-3412
Oct 15, 2026
Merged

polmichel merged 1 commit into
infrahub-developfrom
pmi-number-pool-write-ranges-unset-ifc-3412

Conversation

@polmichel

@polmichel polmichel commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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 opsmill/infrahub#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.

Written for commit 8a04839. Summary will update on new commits.

View guided diff Turn on auto-fix

…hey are not declared

A schema that leaves the ranges out of a NumberPool attribute's parameters
now dumps without them, so a reload keeps the stored ranges, while an
explicit empty list still declares zero ranges.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8a04839
Status: ✅  Deploy successful!
Preview URL: https://a6cd43e8.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pmi-number-pool-write-ranges.infrahub-sdk-python.pages.dev

View logs

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                Coverage Diff                @@
##           infrahub-develop    #1424   +/-   ##
=================================================
  Coverage             86.86%   86.86%           
=================================================
  Files                   152      152           
  Lines                 14813    14813           
  Branches               1982     1982           
=================================================
  Hits                  12867    12867           
  Misses                 1382     1382           
  Partials                564      564           
Flag Coverage Δ
integration-tests 42.38% <0.00%> (-0.08%) ⬇️
python-3.10 60.91% <0.00%> (-0.01%) ⬇️
python-3.11 60.92% <0.00%> (+<0.01%) ⬆️
python-3.12 60.92% <0.00%> (+<0.01%) ⬆️
python-3.13 60.92% <0.00%> (+0.02%) ⬆️
python-3.14 60.92% <0.00%> (+0.02%) ⬆️
python-filler-3.12 22.97% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/schema/generated/write.py 99.40% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@polmichel
polmichel marked this pull request as ready for review October 15, 2026 13:40
@polmichel
polmichel requested a review from a team as a code owner October 15, 2026 13:41
@polmichel polmichel changed the title fix(schema): leave number pool ranges unset in the write model when they are not declared [IFC-3412] fix(schema): leave number pool ranges unset in the write model when they are not declared Oct 15, 2026
@polmichel
polmichel merged commit 583bc73 into infrahub-develop Oct 15, 2026
31 checks passed
@polmichel
polmichel deleted the pmi-number-pool-write-ranges-unset-ifc-3412 branch October 15, 2026 18:51
polmichel added a commit to opsmill/infrahub that referenced this pull request Oct 15, 2026


Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
polmichel added a commit to opsmill/infrahub that referenced this pull request Oct 15, 2026
#11089)

* fix(sdk): leave number pool ranges unset in the generated write model

A schema that leaves the ranges out of a NumberPool attribute's parameters
no longer dumps as one that declares an empty range list. The read model
is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore: regenerate the SDK write model, the OpenAPI schema and the REST types

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(schema): let a reloaded number pool declaration remove every range

A NumberPool attribute reloaded with an explicit `ranges: []` and no
start_range/end_range now declares zero ranges: the stored declaration
drops its ranges or shorthand, the held-number check refuses the load
while objects hold values, and the pool synchronizer empties the pool
otherwise.

Like every other omitted parameter, a reload that leaves the ranges out
keeps the stored ones: omitted `parameters`, `parameters: {}`, and
parameters setting no range key (for example only `allocation_scope`).
An explicitly empty range list stays in the parameters dump, so a load
merged from several files keeps it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(schema): cover number pool declarations reloaded with and without ranges

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore: point python_sdk at the merge of opsmill/infrahub-sdk-python#1424

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
saltas888 added a commit that referenced this pull request Oct 16, 2026
Brings in the number pool changes (#1412, #1424) so that Infrahub develop, which pins 583bc73, can run its CI against this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants