Repository navigation
fix(python): preserve YAML sequence merge precedence on PyYAML 6.0.4 - #782
Merged
christianeu-db merged 1 commit intoNov 21, 2026
Merged
Conversation
PyYAML 6.0.4 removed submerge.reverse() in SafeConstructor.flatten_mapping when expanding sequence merges (<<: [first, second]) and deduplicated keys by id(pair[0].value) from the left, causing later sequence entries to override earlier ones in construct_mapping. Override flatten_mapping in UniqueKeyLoader to reverse sequence merge sources (preserving YAML 1.1 sequence merge precedence across PyYAML 6.0.3 and 6.0.4+) while deduplicating identical key nodes from the right so repeated anchor references cannot expand node.value exponentially.
kayemkim
approved these changes
Nov 21, 2026
kayemkim
left a comment
Member
There was a problem hiding this comment.
Against main's loader on PyYAML 6.0.3, this one gives the same result or the same error for every one of about 19,000 generated merge documents (aliases, nested and repeated merges, sequence merges, = and literal << keys, duplicate keys), on 6.0.3 and on 6.0.4. The fan-out document from PyYAML's own test loads in milliseconds on both versions; with 6.0.3's own flatten it takes about three seconds at ten levels. LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PyYAML 6.0.4 removed
submerge.reverse()inSafeConstructor.flatten_mappingwhen expanding sequence merges (<<: [first, second]) and deduplicated keys byid(pair[0].value)from the left. Becauseconstruct_mappingassigns pairs in forward order (last pair wins), later entries in a sequence merge overwrite earlier ones under PyYAML 6.0.4, breaking YAML 1.1 sequence merge precedence and causingUniqueKeyLoaderTest.test_preserves_merge_precedenceandtest_loading.pyto fail in CI.flatten_mappinginUniqueKeyLoader(python/src/ossie/_loading.py) to reverse sequence merge sources so earlier elements override later ones across both PyYAML 6.0.3 and 6.0.4+, while deduplicating identical key nodes from the right so repeated anchor references cannot expandnode.valueexponentially.python/tests/test_loading.pyto assert expected merged dictionaries directly instead of comparing sequence-merge results againstyaml.safe_load.Testing
uv run --with "pyyaml==6.0.3" validation/test_validate.py(59 passed)uv run --with "pyyaml==6.0.4" validation/test_validate.py(59 passed)uv run --with pytest --with "pyyaml==6.0.3" --with jsonschema --with ./python -m pytest python/tests/(295 passed)uv run --with pytest --with "pyyaml==6.0.4" --with jsonschema --with ./python -m pytest python/tests/(295 passed)