Skip to content

IFC-3676: Leave out empty keys in schema files, keep null in schema format, parse the new schema warnings - #1582

Draft
ogenstad wants to merge 4 commits into
infrahub-developfrom
ifc-3676-schema-null-clears
Draft

ogenstad wants to merge 4 commits into
infrahub-developfrom
ifc-3676-schema-null-clears

Conversation

@ogenstad

@ogenstad ogenstad commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Why

A schema author who loads a schema file cannot remove a value stored on an attribute or relationship, such as parameters.regex. IFC-3337 reports the problem. The server change in opsmill/infrahub#11795 makes an explicit null clear the value. A key left out keeps the stored value.

This pull request makes the SDK and infrahubctl work with that server change. It is tracked in IFC-3676.

What changed

  • SchemaWarningType has two new values, ignored_value and kept_value, so the client can parse a schema load response that contains these warnings.
  • When infrahubctl or a Git repository sync reads a schema file, a key with no value, such as parameters:, is left out, as if the file did not contain it. Only a written null or ~ clears a value.
    • infrahub_sdk.yaml.SchemaLoader is the loader of SchemaFile. It drops each mapping key whose value is a plain empty scalar, at every depth, including keys copied in by a YAML merge key (<<:).
    • Object and menu files still read a key with no value as null.
    • A key tagged !!null with no value, such as regex: !!null, is read in the same way as an empty key, and is left out.
  • infrahubctl schema format:
    • keeps a written null, ~ or NULL as written, and keeps an empty value empty;
    • compares the file before and after formatting with SchemaLoader, so it stops with an error instead of turning an empty value into null or back. It stops on a flow-style mapping with an empty value, such as {name: serial, kind: Text, description: }, because it cannot write that value back as empty;
    • with --strip-defaults, keeps optional: false on attributes, because a schema load keeps the stored optional value when the file leaves out the key.

How to review

  1. infrahub_sdk/yaml.py: SchemaLoader and _is_empty_value.
  2. infrahub_sdk/ctl/schema_format.py: the null-preserving constructor and representer, and the check that uses SchemaLoader.
  3. Tests: tests/unit/sdk/test_yaml.py, tests/unit/ctl/test_schema_format.py, and tests/unit/ctl/test_schema_app.py::test_schema_load_leaves_out_keys_with_no_value, which checks the request that infrahubctl schema load sends.

How to test

uv run pytest tests/unit/sdk/test_yaml.py tests/unit/ctl/test_schema_format.py tests/unit/ctl/test_schema_app.py tests/unit/sdk/test_schema.py

Impact and rollout

Checklist

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

ogenstad and others added 4 commits December 3, 2026 09:40
…lse in schema format

Add the IGNORED_VALUE and KEPT_VALUE schema warning types that Infrahub
returns when a schema load ignores a null or keeps a stored value whose key
the file leaves out.

Keep optional: false on attributes in infrahubctl schema format
--strip-defaults, because a schema load now keeps the stored optional value
when the key is missing.

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

SchemaFile reads its file with a SafeLoader subclass that leaves out each
mapping key whose value is a plain empty null scalar, so only a written
null, ~ or NULL reads as None. Both reading paths (load_content and
load_file_from_disk, single and multiple documents) use it; YamlFile and
InfrahubFile keep the safe loader.

infrahubctl schema format now writes a null it read as null, with the
same text, and keeps an empty value empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… in schema format

The formatter check read an empty key and a written null as the same value, so a
rewrite between them passed unnoticed. A merge key copied empty keys from a mapping
that was not yet constructed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, correct the changelog

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

cloudflare-workers-and-pages Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: ea1957f
Status: ✅  Deploy successful!
Preview URL: https://e94836e5.infrahub-sdk-python.pages.dev
Branch Preview URL: https://ifc-3676-schema-null-clears.infrahub-sdk-python.pages.dev

View logs

@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@                 Coverage Diff                  @@
##           infrahub-develop    #1582      +/-   ##
====================================================
+ Coverage             88.52%   88.60%   +0.08%     
====================================================
  Files                   161      161              
  Lines                 16994    16590     -404     
  Branches               2286     2222      -64     
====================================================
- Hits                  15044    14700     -344     
+ Misses                 1362     1321      -41     
+ Partials                588      569      -19     
Flag Coverage Δ
integration-tests 42.10% <61.76%> (-0.58%) ⬇️
python-3.10 65.13% <94.11%> (+0.13%) ⬆️
python-3.11 65.12% <94.11%> (+0.11%) ⬆️
python-3.12 65.12% <94.11%> (+0.11%) ⬆️
python-3.13 65.12% <94.11%> (+0.12%) ⬆️
python-3.14 65.13% <94.11%> (+0.12%) ⬆️
python-3.15 65.12% <94.11%> (+0.11%) ⬆️
python-filler-3.12 21.82% <5.88%> (-0.17%) ⬇️

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.79% <100.00%> (+0.24%) ⬆️
infrahub_sdk/schema/__init__.py 75.29% <100.00%> (+1.26%) ⬆️
infrahub_sdk/yaml.py 89.55% <100.00%> (+0.84%) ⬆️

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