Skip to content

Fix out-of-order AoT element extensions - #578

Open
davidpavlovschi wants to merge 1 commit into
python-poetry:masterfrom
davidpavlovschi:fix/aot-out-of-order-unwrap
Open

Fix out-of-order AoT element extensions#578
davidpavlovschi wants to merge 1 commit into
python-poetry:masterfrom
davidpavlovschi:fix/aot-out-of-order-unwrap

Conversation

@davidpavlovschi

@davidpavlovschi davidpavlovschi commented Jul 28, 2026

Copy link
Copy Markdown

Summary

Fixes #577.

An array-of-tables element can be extended by a later nested table header:

[[y.a]]
name = "first"

[unrelated]

[[y.a.c]]
kind = "child"

This document is valid and parse() already preserves it byte-for-byte. Because the unrelated table splits y into out-of-order parts, accessing doc["y"] or calling doc.unwrap() currently tries to append the later implicit a table beside the earlier a AoT and raises KeyAlreadyPresent.

OutOfOrderTableProxy._merge_aot_fragment() now handles this AoT + super-table combination by presenting the last AoT element through a nested proxy spanning both live source tables. It does not merge either source in place, so the original headers keep rendering in their original locations. Reads and unwrap() see the combined element, while edits route back to the correct source part.

Starting a subsequent [[y.a]] element after that nested extension is also valid, but currently fails during parsing because the new fragment is merged only against the last out-of-order part. Once a key is already out of order, the parser now preserves each later super-table as another part and lets the complete proxy/validation path merge it against all prior parts.

The regression test verifies:

  • exact round-tripping before mutation;
  • the unwrapped result against the tomllib interpretation;
  • parsing and merging a subsequent AoT element after the nested extension;
  • write-through for an original element key, a key inside the later nested AoT, and a newly added key;
  • valid round-tripping after those mutations.

Validation:

  • 1052 passed
  • 96 generated valid permutations matched tomllib, round-tripped exactly, and survived live mutation
  • Ruff check and format check pass
  • git diff --check passes

Agent Drafting Metadata

  • Agent: OpenAI Codex
  • Model: GPT-5 family Codex
  • Notes: David authorized the contribution. I reproduced the report against tomllib, traced the failure to the out-of-order proxy merge, implemented the live-view fix, and ran the complete test suite and formatting checks before opening this PR.

@davidpavlovschi
davidpavlovschi force-pushed the fix/aot-out-of-order-unwrap branch from 54ddd95 to 2f7a2a5 Compare July 28, 2026 19:43
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.

unwrap raises KeyAlreadyPresent for an out-of-order AoT element extension

1 participant