Skip to content

Fix AttributeError on an out-of-order table under an indented header - #663

Open
cig13zs wants to merge 2 commits into
python-poetry:masterfrom
cig13zs:fix-nested-oot-trivia
Open

cig13zs wants to merge 2 commits into
python-poetry:masterfrom
cig13zs:fix-nested-oot-trivia

Conversation

@cig13zs

@cig13zs cig13zs commented Oct 15, 2026

Copy link
Copy Markdown

Fixes #661. Table.append copies the parent's indent onto the item it just stored, but when that key is split out of order the lookup returns an OutOfOrderTableProxy, which has no trivia. The fix skips the proxy, since its parts already keep their own indentation. #263 was the same crash one level up and only stopped happening because the outermost super table has no indent.

Parsing " [a.b.c.d]\n[a.b.c]" raised "'OutOfOrderTableProxy' object has
no attribute 'trivia'". The intermediate tables created for an indented
header carry its indent, and Table.append copies that indent onto the
item it just stored. When that key is now split out of order, the lookup
returns an OutOfOrderTableProxy, which has no trivia.

Skip the indent copy for the proxy; its parts keep their own
indentation. Issue python-poetry#263 was the three-level form of this, which only
stopped failing because the outermost super table has no indent.

@Wkhanex Wkhanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted validation at d0484992a8bd on Python 3.12.14: I expanded the indentation case to spaces, a tab, and mixed space/tab indentation at depths 4–6, for both a table and an array of tables. Each input also had an intervening unrelated table and a value added through the reopened parent. All 18 combinations parsed and preserved the original text before mutation, and their serialized data after mutation matched tomllib. The 23 focused out-of-order tests passed.

The mutation check matters here because skipping proxy trivia must leave its component tables usable after the initial parse, as well as avoid the AttributeError. I did not find a discrepancy in those cases.

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.

AttributeError on an out-of-order table under an indented header (4+ levels)

2 participants