Skip to content

fix(schema): accept state on a dropdown choice in the write contract - #1498

Draft
ogenstad wants to merge 1 commit into
infrahub-developfrom
pog-em/dropdown-choice-state
Draft

ogenstad wants to merge 1 commit into
infrahub-developfrom
pog-em/dropdown-choice-state

Conversation

@ogenstad

@ogenstad ogenstad commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A team removes one dropdown choice by setting state: absent on it in a schema file. The SDK write model of a choice has no state field, so validate_schema reports choices.state as a read-only field and Infrahub ignores the value. This PR adds state to DropdownChoiceWrite. The Infrahub change that removes the choice is in opsmill/infrahub#11493. The analysis is in opsmill/infrahub#10938.

Changes to the generated write contract

  • DropdownChoiceWrite declares state (enum SchemaState, default present). The field is generated from the state field of attributes in Infrahub's internal.py.
  • READ_ONLY_FIELDS["DropdownChoiceWrite"] now lists only id.
  • DropdownChoiceRead is unchanged, so the schema read API does not return state on choices.

Changes to validation and formatting results

  • validate_schema accepts state: absent on a choice without a warning.
  • A state value other than present or absent on a choice is reported as an error.
  • infrahubctl schema format places state after the other keys of a choice.

Tests

  • tests/unit/test_schema_offline_validation.py:
    • the choice case now expects only id to be reported as read-only;
    • new test: state: absent on a Dropdown choice is accepted without a warning;
    • new case: a choice state value outside the enum is reported as an error.
  • tests/unit/ctl/test_schema_format.py: new test for the position of state in a choice. It fails without the CHOICE_ORDER change.

🤖 Generated with Claude Code

`state: absent` on a dropdown choice is how a schema file removes that
choice. The generated `DropdownChoiceWrite` model now declares `state`
(enum `SchemaState`, default `present`), so `validate_schema` accepts it
without the read-only warning and only `id` stays read-only on a choice.
The read model is unchanged, so the schema read API does not return
`state` on choices.

`infrahubctl schema format` now places `state` after the other keys of
a choice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: e5d1ed6
Status: ✅  Deploy successful!
Preview URL: https://430ed244.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pog-em-dropdown-choice-state.infrahub-sdk-python.pages.dev

View logs

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                 Coverage Diff                  @@
##           infrahub-develop    #1498      +/-   ##
====================================================
- Coverage             87.85%   87.84%   -0.01%     
====================================================
  Files                   157      157              
  Lines                 15656    15654       -2     
  Branches               2114     2114              
====================================================
- Hits                  13754    13752       -2     
  Misses                 1341     1341              
  Partials                561      561              
Flag Coverage Δ
integration-tests 42.94% <50.00%> (+0.28%) ⬆️
python-3.10 62.91% <50.00%> (+<0.01%) ⬆️
python-3.11 62.89% <50.00%> (-0.02%) ⬇️
python-3.12 62.91% <50.00%> (-0.01%) ⬇️
python-3.13 62.89% <50.00%> (-0.02%) ⬇️
python-3.14 62.91% <50.00%> (+<0.01%) ⬆️
python-3.15 62.91% <50.00%> (+<0.01%) ⬆️
python-filler-3.12 23.03% <50.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
infrahub_sdk/ctl/schema_format.py 97.54% <100.00%> (ø)
infrahub_sdk/schema/generated/contract.py 100.00% <ø> (ø)
infrahub_sdk/schema/generated/write.py 99.40% <100.00%> (+<0.01%) ⬆️

... and 2 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant