Repository navigation
fix(yaml): give earlier map precedence in a << merge sequence - #4995
PratikDhanave wants to merge 1 commit into
Conversation
A `<<: [*a, *b]` sequence merge was resolving keys to the LAST map in the sequence, but the YAML merge spec (and PyYAML's safe_load / flatten_mapping) give the EARLIER map precedence. _mapping_pairs fed the sources forward into a last-write-wins dict, so for a key defined in both anchors the later anchor's value and line won instead of the earlier one's. Feed the merge sources in reverse, mirroring PyYAML's flatten_mapping (which reverses the submerge), so the earliest map keeps the final value/line. Regression test asserts services.web.common resolves to the first anchor's mapping (L2), matching yaml.safe_load, not the second anchor's (L5).
|
Thanks for the pull request, @PratikDhanave. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.
Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).
Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).
Not verified on this run: \_mapping\_pairs (vacuous: never exercised).
Graphify review — findings
Fixes YAML merge-key handling so that in a <<: [*a, *b] sequence the earlier map wins over the later one, as the YAML merge spec and PyYAML's safe_load do. _mapping_pairs now feeds the merge sources in reverse, so the last-write-wins dict ends up with the first map's value and source line for any duplicate key. Adds a regression test where both anchors define common and checks that services.web.common resolves to *a's key at L2, not *b's at L5.
No blocking issues surfaced.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 46 functions depend on the 46 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract_yaml()— 18 callers, 9 callees
Verification — 46 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 46 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
1 of 518 test file(s) selected (0%) via static blast radius.
tests/test_yaml_extraction.py— impact, changed-test
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
Could not verify: Could not verify \_mapping\_pairs.
The verifier did not have enough to check \_mapping\_pairs, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 16 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
· 1 more finding(s) on lines outside this diff (see the check run).
…ractor fixes #5003 (C# preprocessor blanking), #5005/#5001 (Solidity library + emit/revert/ require linking) and #4995 (YAML << merge precedence) each change per-file extractor output; fold them into one schema-38 entry so warm caches re-run. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in 0.9.103 (published to PyPI), cherry-picked with your authorship preserved. Folded into the combined 38 schema bump (per-file YAML source-line output changes). Thanks @PratikDhanave. |
What does this PR do?
Fixes a YAML merge-key precedence bug in the structural YAML extractor
(
graphify/extractors/yaml_config.py,_mapping_pairs).For a sequence merge
<<: [*a, *b], the YAML 1.1 merge spec gives the earliermap precedence over the later one, and PyYAML's
safe_load/flatten_mappinghonor this (flatten reverses the submerge so the first map's keys win). The
extractor instead fed the merge sources forward into a last-write-wins dict, so a
key defined in both anchors ended up resolving to the later map's value and
line — the opposite of the spec and of
safe_load.Concretely, given:
yaml.safe_load(...)["services"]["web"]["common"]is*a's mapping (from_a,whose key is at L2), but the extractor was emitting the
web.commonnode at*b'sline (L5).
Type of change
Verification & Invariants
Invariant protected: the extractor's "keys as written" view
(
_mapping_pairsover the composed node tree) must agree with the value PyYAMLactually constructs via
safe_load. The fix feeds the merge sources in reverse,mirroring
flatten_mapping, so the earliest map keeps the final value/line.Fail-pre / pass-post evidence (new test
tests/test_yaml_extraction.py::test_merge_key_sequence_earlier_map_wins):Before the fix (test fails):
After the fix (full file passes, incl. the existing merge test):
How was this tested?
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments.