IFC-3676: Leave out empty keys in schema files, keep null in schema format, parse the new schema warnings
Draft
OG
1d ago+393+393+012345678901234567890123456789-13-13-01234567890123456789
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
SchemaWarningTypehas two new values,ignored_valueandkept_value, so the client can parse a schema load response that contains these warnings.- When
infrahubctlor a Git repository sync reads a schema file, a key with no value, such asparameters:, is left out, as if the file did not contain it. Only a writtennullor~clears a value.infrahub_sdk.yaml.SchemaLoaderis the loader ofSchemaFile. 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
!!nullwith no value, such asregex: !!null, is read in the same way as an empty key, and is left out.
infrahubctl schema format:- keeps a written
null,~orNULLas 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 intonullor 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, keepsoptional: falseon attributes, because a schema load keeps the storedoptionalvalue when the file leaves out the key.
- keeps a written
How to review
infrahub_sdk/yaml.py:SchemaLoaderand_is_empty_value.infrahub_sdk/ctl/schema_format.py: the null-preserving constructor and representer, and the check that usesSchemaLoader.- Tests:
tests/unit/sdk/test_yaml.py,tests/unit/ctl/test_schema_format.py, andtests/unit/ctl/test_schema_app.py::test_schema_load_leaves_out_keys_with_no_value, which checks the request thatinfrahubctl schema loadsends.
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
- Backward compatibility: a schema file with an empty key, such as
parameters:, is now sent without that key. Against a server without the change in opsmill/infrahub#11795 the result is the same as before, because that server ignores anull. - Deployment notes: this pull request merges before the Infrahub feature branch in opsmill/infrahub#11795 merges into
develop. That branch then moves thepython_sdksubmodule to the head ofinfrahub-develop.
Checklist
- Tests added/updated
- Changelog entry added
- External docs updated (the Infrahub docs change is in opsmill/infrahub#11795)
- Internal .md docs updated (the internal docs change is in opsmill/infrahub#11795)
š¤ Generated with Claude Code