Skip to content

Fix stale dotted-key prefix when replacing a table value with a plain dict#528

Closed
gaoflow wants to merge 1 commit into
python-poetry:masterfrom
gaoflow:fix-524-dotted-key-replace-prefix
Closed

Fix stale dotted-key prefix when replacing a table value with a plain dict#528
gaoflow wants to merge 1 commit into
python-poetry:masterfrom
gaoflow:fix-524-dotted-key-replace-prefix

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #524.

After parsing fruit.apple = true, the document-body key fruit retained _dotted=True from _handle_dotted_key. When the whole table is later replaced via doc['fruit'] = {'a': 1}, _replace_at reuses the old key object (same name + same kind), keeping the stale flag. This causes rendering to both emit a [fruit] header (new table is not a super-table) and prefix every child with fruit. (because key.is_dotted() is true), producing:

[fruit]
fruit.a = 1

instead of the correct a = 1.

The fix clears _dotted on the reused key in _replace_at. The dotted heritage belongs to the original parse — a full table replacement gets fresh rendering behaviour. Incremental modifications (like doc['fruit']['banana'] = 2) are unaffected because they only reach the table-level _replace_at, not the document-level one that reuses the dotted-marked outer key.

… dict

After parsing 'fruit.apple = true', the key 'fruit' in the document
body retained _dotted=True from _handle_dotted_key.  When the entire
table was then replaced via doc['fruit'] = {'a': 1}, _replace_at
reused the old key object (same name + same kind), keeping the stale
_dotted flag.  This caused rendering to both emit a [fruit] header
(because the new table is not a super-table) and prefix every child
with 'fruit.' (because key.is_dotted() was true), producing the
invalid output '[fruit]\nfruit.a = 1' instead of 'a = 1'.

Fix: clear _dotted on the reused key in _replace_at.  The dotted
heritage belongs to the original parse — a full table replacement
gets fresh rendering behaviour.  Incremental modifications (like
doc['fruit']['banana'] = 2) are unaffected because they don't
reach the document-level _replace_at path.
@gaoflow

gaoflow commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #526 which fixes both #524 and #513 with a more comprehensive approach.

@gaoflow gaoflow closed this Jun 18, 2026
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.

Assigning a dict over a dotted key renders a stale parent. prefix

1 participant