python-poetry / python-poetry/tomlkit

unwrap raises KeyAlreadyPresent for an out-of-order AoT element extension

Open
#577 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
850
Forks
162
Avg merge
13m
Merged PRs (30d)
2

Description

Description

tomlkit.parse() accepts and exactly round-trips this valid document, but accessing doc["y"] or calling doc.unwrap() raises KeyAlreadyPresent: Key "a" already exists:

from tomlkit import parse

content = """\
[[y.a]]
[b.d.x]
[[y.a.c]]
"""

doc = parse(content)
assert doc.as_string() == content
doc.unwrap()  # KeyAlreadyPresent: Key "a" already exists

Python's standard-library tomllib reads it as:

{"y": {"a": [{"c": [{}]}]}, "b": {"d": {"x": {}}}}

The later [[y.a.c]] header extends the last element of the existing y.a array of tables. This works when the parts are adjacent, but an unrelated table makes y out of order. OutOfOrderTableProxy then sees a first as an AoT and later as an implicit Table; its existing fragment merge handles AoT + AoT, but not this AoT + super-table extension.

The example was initially flagged by @chuenchen309 in the description of #565. I reproduced it on current master and narrowed it down to the proxy merge path.

Environment

  • tomlkit 0.15.1 / current master
  • Python 3.12

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing tomlkit.parse(), doc["y"], doc.unwrap(), and the OutOfOrderTableProxy merge path described in the issue. Reproduce the supplied document and verify that accessing y and unwrapping no longer raises KeyAlreadyPresent while doc.as_string() still exactly matches the input.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.