Skip to content

Fix sub-table of a dotted key escaping its parent header path (#557)#568

Open
earfman wants to merge 3 commits into
python-poetry:masterfrom
earfman:earfman-patch-1
Open

Fix sub-table of a dotted key escaping its parent header path (#557)#568
earfman wants to merge 3 commits into
python-poetry:masterfrom
earfman:earfman-patch-1

Conversation

@earfman

@earfman earfman commented Jul 20, 2026

Copy link
Copy Markdown

Fixes #557.

Problem

Assigning a sub-table under a dotted-key super-table nested inside a real table caused the sub-table header to lose its parent path on render:

doc = tomlkit.loads("\n[t]\na.b = 1\n")
doc["t"]["a"]["c"] = {}
tomlkit.dumps(doc)
# [t]
# a.b = 1
#
# [a.c]   <- escapes [t]; `c` is lost from t.a and reappears at the document root

parse(dumps(doc)) != doc, so this is a round-trip / data-loss bug. The same happened inside array-of-tables elements ([[servers]] produced [a.c] instead of [servers.a.c]).

Cause

In Container._render_table, prefix served two purposes at once: the relative dotted-key prefix used for leaf items (so a.b stays inline under [t]) and the absolute header path used for nested sub-tables (which need [t.a.c]). The "dotted key inside table" branch dropped the prefix entirely — right for the leaf, wrong for a real sub-table nested underneath, which then lost the t. parent path. _render_aot_table had the same issue.

Fix

Track the absolute header path separately via a new header_prefix argument. Leaf items continue to render off the relative key; nested sub-table and array-of-tables headers render off the absolute path. When a table carries a display_name (from a parsed explicit header) the two paths coincide, so existing output is unchanged.

Tests

Added regression tests covering the table case, a chained dotted parent (a.b.x — the leaf stays relative while the sub-table header is absolute), and the array-of-tables case. The full suite passes (1053 tests).


verified by Coretexa

Found and fixed with an integrity-first pipeline; the fix was independently verified by a separate agent than the one that found it before submission.

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.

table escapes its parent

1 participant