Skip to content

feat(schema): number pool ranges and allocation scope - #1412

Draft
polmichel wants to merge 2 commits into
infrahub-developfrom
feature-number-pools-1.12
Draft

polmichel wants to merge 2 commits into
infrahub-developfrom
feature-number-pools-1.12

Conversation

@polmichel

@polmichel polmichel commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Why

Infrahub 1.12 lets a number pool allocate from several weighted ranges, and divide its space by an allocation scope. A user declares both in a schema file, so neither is usable until the generated write models accept them and the generated read models return them.

The four changed modules are generated from Infrahub's own core schema definitions by invoke backend.generate, which writes into this submodule. The definitions they come from live on the Infrahub branch feature-number-pools-1.12 and are not on Infrahub develop yet.

Non-goal: this branch adds no behaviour of its own. Allocation across ranges and the scope check are implemented in the Infrahub backend.

What changed

Behavioural changes:

  • A schema file can declare parameters.ranges on a NumberPool attribute: a list of start/end ranges with an optional weight. Until now the schema load endpoint dropped the value, because the write models set extra="ignore".
  • A schema file can declare parameters.allocation_scope: the fields of the kind that divide the pool's space.
  • start_range and end_range become optional and carry no default. A NumberPool attribute declared without any range is submitted as such, instead of receiving 1 to 9223372036854775807. Both stay accepted, deprecated in favour of ranges.
  • The schema read endpoint returns ranges and allocation_scope.
  • infrahub_sdk.protocols exposes CoreNumberPoolRange and CoreNumberPoolRangeSync, and CoreNumberPool carries ranges and allocation_scope.

What stayed the same: no hand-written SDK module changed. The four changed modules are generated, and infrahub_sdk/protocols_generator/ is untouched.

Commits:

How to review

Reviewing the generated modules on their own says little. The source of truth is backend/infrahub/core/schema/definitions/core/resource_pool.py and backend/infrahub/core/schema/attribute_parameters.py on the Infrahub branch feature-number-pools-1.12.

Three consumers in the Infrahub backend read these models directly:

  • backend/infrahub/api/schema.py — SchemaLoadAPI subclasses InfrahubSchemaWrite.
  • backend/infrahub/schema/read_schema.py — build_read_schema projects onto BaseNodeSchemaRead.
  • backend/infrahub/core/schema/write_json_schema.py — reads READ_ONLY_FIELDS and InfrahubSchemaWrite.

How to test

uv run pytest tests/unit/test_schema_offline_validation.py

From an Infrahub checkout pinning this branch, the generated files must match what the branch's definitions produce:

invoke backend.validate-generated

Impact & rollout

  • Backward compatibility: start_range and end_range are still accepted. Dropping their defaults changes what reaches the server for a NumberPool attribute declared without any range.
  • Deployment notes: [CLAUDE RECOMMENDED – based on the submodule pins read from git ls-tree and the validate_generated task in tasks/backend.py] This branch should be merged in the same window as the Infrahub branch feature-number-pools-1.12, not before it. Infrahub develop pins SDK commit 2ac1179 explicitly, so merging here does not break it immediately; but the first bump of that pin to the new infrahub-develop tip would fail validate_generated, because develop's core models do not declare these fields.

Checklist

  • Tests added/updated
  • Changelog entry added
  • External docs updated (if user-facing or ops-facing change)
  • Internal .md docs updated

Assisted-by: opsmill-dev-pr 0.2.0

🤖 Generated with Claude Code


Summary by cubic

The generated SDK models now accept parameters.ranges and parameters.allocation_scope on NumberPool attributes, so a schema file can declare several weighted ranges and divide a pool's space by kind fields.

  • start_range/end_range become optional and deprecated; a NumberPool declared without any range is submitted as such, instead of receiving a default 1 to 9223372036854775807.
  • The schema read endpoint returns ranges and allocation_scope, and infrahub_sdk.protocols gains CoreNumberPoolRange/CoreNumberPoolRangeSync.
  • The four changed modules are generated from Infrahub's core schema definitions; no hand-written SDK code changed.

Rollout

  • Merge alongside the Infrahub branch feature-number-pools-1.12, not before it. A subsequent pin bump on Infrahub develop would fail validate_generated because develop's core models do not declare these fields.

Written for commit 1bd89c8. Summary will update on new commits.

View guided diff Turn on auto-fix

polmichel and others added 2 commits October 8, 2026 09:13
* chore: regenerate protocols for the number pool range kind

CoreNumberPool gains a ranges relationship and its start_range and end_range
become optional; the new CoreNumberPoolRange kind is added.

Generated from the Infrahub core models, not written by hand.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TgXERZQRu7W5V8zCyUEAVA

* test(protocols): regenerate golden fixtures for the number pool range kind

The generator builds its import line by introspecting infrahub_sdk.protocols,
so regenerating that module in 100d6b3 to add CoreNumberPoolRange changed the
output for every user schema. The golden fixtures still carried the previous
import line, failing test_render_user_schema_matches_golden.

Only line 9 changes in each fixture, gaining CoreNumberPoolRange and
CoreNumberPoolRangeSync.

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

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
…d schema models (#1402)

* feat(schema): accept number pool ranges in the generated schema models

NumberPool attribute parameters carry `ranges`, a list of start/end ranges with
an optional weight, next to the `start_range`/`end_range` shorthand. The
shorthand is optional and deprecated, so an attribute declared without any range
no longer receives a default range. Bookkeeping fields on a range are reported
as read-only like on every other value model.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* docs(schema): state the default of a missing number pool bound

The generated descriptions of start_range and end_range now say that a
missing start defaults to 1 and a missing end to the largest supported
number when only the other bound is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(schema): accept the number pool allocation_scope in the generated schema models

Regenerate the schema models and protocols for Infrahub's new
`allocation_scope` field: `NumberPoolParametersRead`/`Write` gain
`allocation_scope: list[str] | None`, and `CoreNumberPool` gains the
matching optional List attribute. Without it, a schema read from
Infrahub and loaded back is rejected because the field is unknown.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* drop changelog

---------

Co-authored-by: Pol Michel <polmichel29@gmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
@polmichel polmichel added the type/feature New feature or request label Oct 9, 2026
@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                 Coverage Diff                  @@
##           infrahub-develop    #1412      +/-   ##
====================================================
- Coverage             87.14%   86.82%   -0.32%     
====================================================
  Files                   153      152       -1     
  Lines                 16493    14775    -1718     
  Branches               2417     1982     -435     
====================================================
- Hits                  14372    12829    -1543     
+ Misses                 1493     1382     -111     
+ Partials                628      564      -64     
Flag Coverage Δ
integration-tests 42.36% <55.00%> (-1.25%) ⬇️
python-3.10 60.91% <55.00%> (-1.14%) ⬇️
python-3.11 60.91% <55.00%> (-1.14%) ⬇️
python-3.12 60.91% <55.00%> (-1.14%) ⬇️
python-3.13 60.90% <55.00%> (-1.15%) ⬇️
python-3.14 60.91% <55.00%> (-1.14%) ⬇️
python-filler-3.12 22.94% <45.00%> (+0.37%) ⬆️

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

Files with missing lines Coverage Δ
infrahub_sdk/protocols.py 100.00% <100.00%> (ø)
infrahub_sdk/schema/generated/contract.py 100.00% <ø> (ø)
infrahub_sdk/schema/generated/read.py 100.00% <100.00%> (ø)
infrahub_sdk/schema/generated/write.py 99.40% <100.00%> (+0.02%) ⬆️

... and 15 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants