Skip to content

Merge AoT fragments when building an out-of-order table proxy#507

Open
gaoflow wants to merge 2 commits into
python-poetry:masterfrom
gaoflow:fix-505-out-of-order-aot
Open

Merge AoT fragments when building an out-of-order table proxy#507
gaoflow wants to merge 2 commits into
python-poetry:masterfrom
gaoflow:fix-505-out-of-order-aot

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #505.

When an array of tables is split across out-of-order parts of the same table, OutOfOrderTableProxy.__init__ fed both fragments to _raw_append, which only knows how to chain duplicate Table parts and raised KeyAlreadyPresent. Since the proxy is also built by __contains__, valid documents (accepted by tomllib) failed at parse time once a [hooks.*] header followed the second fragment.

The fragments are now presented as a new merged AoT that references the live element tables — neither fragment is mutated, so the table parts keep rendering their own elements (round-trip stays byte-identical) and element-level mutations through the proxy still write through to the document. This mirrors the isolation note in OutOfOrderTableProxy.validate, which deep-copies for the same reason.

The reported config only reproduces when the repeated AoT is genuinely out of order (split by an unrelated table) — contiguous repeats as literally pasted in the issue already worked; verified the merged result matches tomllib for both shapes.

@gaoflow gaoflow force-pushed the fix-505-out-of-order-aot branch from 065f3d2 to a7993c2 Compare June 12, 2026 08:48
When an array of tables is split across out-of-order parts of the same
table, OutOfOrderTableProxy fed both fragments to _raw_append, which
only knows how to chain duplicate Table parts and raised
KeyAlreadyPresent. Valid documents like

    [hooks]
    [[hooks.Stop]]
    [unrelated]
    [[hooks.Stop]]
    [hooks.state]

failed at parse time (the proxy is also built by __contains__). The
fragments are now presented as a new merged AoT referencing the live
element tables, so neither fragment is mutated and the parts keep
rendering their own elements.

Fixes python-poetry#505
@gaoflow gaoflow force-pushed the fix-505-out-of-order-aot branch from a7993c2 to fa0f69e Compare June 12, 2026 09:33
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.

KeyAlreadyPresent when accessing valid TOML with repeated array tables under an out-of-order table

2 participants