Repository navigation
fix(python): reject duplicate keys when loading documents - #618
Conversation
Generated-by: OpenAI Codex
|
|
||
| if isinstance(node, yaml.MappingNode): | ||
| seen = set() | ||
| merge_key = object() |
There was a problem hiding this comment.
This now rejects a mapping with more than one << merge key, e.g. {<<: *a, <<: *b}, with "found duplicate key '<<'.
YAML 1.1 allows repeated merge keys, and PyYAML's flatten_mapping merges all of them, so this input loaded before this change.
Can we skip << duplicate check?
The merge keys should be expanded first and only explicit keys compared. The test that asserts the rejection would need to change too.
| from yaml.constructor import ConstructorError | ||
|
|
||
|
|
||
| class UniqueKeyLoader(yaml.SafeLoader): |
There was a problem hiding this comment.
This UniqueKeyLoader is nearly identical to the one in validation/validate.py, and the comment says it is written to match it.
With two copies, a later fix to merge-key or alias handling can land in only one of them.
The validator and OssieDocument.from_ossie_yaml would then disagree on whether the same document is valid.
Could both import shared one implementation?
Generated-by: OpenAI Codex
|
Thanks @jbonofre. Fixed both comments! |
|
I will merge as soon as CI is green 😄 |
Bring in apache#596 (compliance portability fixtures), apache#618 (reject duplicate keys on load), and apache#629 (ATACCAMA vendor) from main. The only conflict was the import block of validation/validate.py, where this branch adds `difflib` plus the `Expression` dataclass/iterator imports and apache#618 adds `importlib.util` for the shared `_loading.py` bootstrap; resolved by keeping the union. apache#618's loader refactor merged cleanly onto the expression-iterator refactor, and apache#629's OssieVendor enum entry is complementary to this branch's vendors.md ATACCAMA row. Verified against validation-ci.yml: duplicate-key tests (59), validation pytest (268), python model tests (266), generator --check in sync, and all five example validations pass. Co-authored-by: Isaac <no-reply@databricks.com>
apache/ossie#617 adds expression.sql, the portable form in OSSIE_SQL_2026, makes dialects optional beside it, and turns a dialect into any string. model.expression_text is now the one place that picks the text: sql, then an OSSIE_SQL_2026 entry, then ANSI_SQL. The pin also brings apache/ossie#618: a repeated key in a YAML or JSON file is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
The SDK document loaders silently keep the last value of a duplicate YAML or JSON key. For example, a repeated metric
expressioncan replaceSUM(orders.amount)withAVG(orders.amount)before validation sees it.Reject duplicate keys before constructing the model. The SDK and validator now use one
UniqueKeyLoaderimplementation. Repeated YAML merge directives, merge precedence, explicit overrides and reused aliases remain supported. Explicit duplicates inside merge sources are still rejected.From a checkout, the validator loads the shared file directly, preserving converter environments that do not install the SDK. A copied validator uses an installed SDK; this is documented in the script.
Related Issues
Follow-up to #336/#337 (CLI duplicate-key checks) and #563 (SDK document loaders).
Validation
E4,E7,E9,F,I), whitespace and Apache RAT checks pass.Checklist
Prepared with OpenAI Codex. Reproductions and tests were run locally.