Emptying a nested array of tables before an out-of-order super-table renders invalid TOML (0.15.2, since #567)
維護者通常 2 天內回覆
評估
研究方向
Start by running the reproduction in the issue: parse the [[a.b.c]] document, pop the element, and inspect the tomlkit.dumps output. The bug is in how an emptied array of tables is rendered when its super-table comes later in the document, which #567 changed; the issue says the parent commit of #567 produces valid output. Done when the output parses with both tomlkit.parse and tomllib.loads to {'a': {'b': {'c': []}, 'y': 1}}.
由索引模型根據 Issue 內容生成。
描述
Versions tested: tomlkit 0.15.2 (tag a0b15eb), and master at d7def7d (2026-10-29); Python 3.12.
Reproduce:
import tomlkit
doc = tomlkit.parse("[[a.b.c]]\nx = 1\n\n[a]\ny = 1\n")
doc["a"]["b"]["c"].pop()
out = tomlkit.dumps(doc)
print(repr(out))
tomlkit.parse(out)
The input is valid TOML, and tomlkit parses it to {'a': {'b': {'c': [{'x': 1}]}, 'y': 1}}. After the pop, doc.unwrap() is {'a': {'b': {'c': []}, 'y': 1}}, as expected.
Observed: dumps returns 'a.b.c = []\n[a]\ny = 1\n', which declares a twice:
tomlkit.exceptions.ParseError: Redefinition of an existing table at line 3 col 0
tomllib.loads rejects it too: Cannot declare ('a',) twice (at line 2, column 3).
Expected: output that parses back to {'a': {'b': {'c': []}, 'y': 1}}, for example what tomlkit.dumps(doc.unwrap()) returns:
[a]
y = 1
[a.b]
c = []
Where it comes from: #567 renders an emptied array of tables as key = []. When the array sits under a super-table that is defined later in the document, the dotted key is emitted where the [[a.b.c]] header was, before [a]. On the parent commit of #567, the same steps produce output that parses. The same happens when [a] extends a.b with a dotted key, for example [[a.b.c]]\nx = 1\n[a]\nb.z = 1\n.
Related: #553, which #567 addressed in part, and #675, another failure after removing an element from an out-of-order table.
This came up while running generated tests on pairs of tomlkit pull requests that were open at the same time (#565 and #567). The reproduction above gives the same output on 0.15.2 and on master.
- 主要語言
- Python
- 星號
- 864
- 分支
- 207
- 平均合併
- 3 天 22 小時
- 30 天內合併 PR
- 25
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 沒有貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python-poetry/tomlkit 的其他 Issue
-
`update()` on an out-of-order table raises `IndexError` after a sub-table fragment was popped可能已有人在做 @rajmodi8905 於 13 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 68/100
python-poetry/tomlkit#675 · 3 則留言 ·
維護者通常 2 天內回覆
-
AttributeError on an out-of-order table under an indented header (4+ levels)可能已有人在做 @cig13zs 於 20 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 18/100
python-poetry/tomlkit#661 ·
維護者通常 2 天內回覆
-
In-place array repetition changes values without updating serialized TOML可能已有人在做 @harbinresearcher 於 23 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 35/100
python-poetry/tomlkit#646 · 1 則留言 ·
維護者通常 2 天內回覆
-
tomlkit 0.15.1 fails on out-of-order table header可能重新可做 關聯的 PR 已關閉且未合併。 未關閉
難度 4/5 3-5 天 新手友好度 45/100
python-poetry/tomlkit#632 ·
維護者通常 2 天內回覆
-
`dumps(sort_keys=True)` only sorts the top level of a parsed document (nested tables / inline tables / AoT keep original order)可能已有人在做 @Sreekant13 於 36 天前認領。 未關閉
難度 5/5 一週以上 新手友好度 35/100
python-poetry/tomlkit#614 · 2 則留言 ·
維護者通常 2 天內回覆
查看 python-poetry/tomlkit 的全部 Issue
相似的 Issue
-
bug module:nodes tests
難度 2/5 1-3 小時 新手友好度 78/100
rocketride-org/rocketride-server#3020 ·
維護者通常 2 天內回覆
-
難度 1/5 1 小時以內 新手友好度 90/100
bretterer/home-assistant-rivian#335 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 68/100
mampfes/hacs_waste_collection_schedule#8114 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
TIGER-AI-Lab/ClawBench#475 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
UKGovernmentBEIS/inspect_ai#6322 ·
維護者通常 1 天內回覆