You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Failed to delete an item of OutOfOrderTableProxy #383
In this case, item.value.body contains two keys called pdm (I think maybe there should only be one?)
[(<Key pdm>, {'scripts': {}}), (<Key pdm>, {})]
So we go around the for k, v in item.value.body: loop twice, adding the same table_idx (zero) twice to self._tables_map[k].- Then in __del__ we try to delete the same key twice, but it fails the second time because it's already been deleted.
I made a small change to __init__ to avoid adding the same key twice:
key_to_index = self._tables_map.setdefault(k, [])
if table_idx not in key_to_index:
key_to_index.append(table_idx)
if k is not None:
dict.__setitem__(self, k.key, v)
And it appears to work, for this case and a few other simple sanity checks:
python3.12 -c 'import tomlkit
with open("pyproject.toml", "rb") as f: k=tomlkit.load(f); del k["tool"]["pdm"]; print(tomlkit.dumps(k))'
[dependency-groups]
[tool.ruff]
Activity
qris commentedon Jan 31, 2025
I think this may be the same bug:
Outputs:
Deleting other keys works fine.
I traced the problem to here, in
OutOfOrderTableProxy.__init__:In this case,
item.value.bodycontains two keys calledpdm(I think maybe there should only be one?)So we go around the
for k, v in item.value.body:loop twice, adding the sametable_idx(zero) twice toself._tables_map[k].- Then in__del__we try to delete the same key twice, but it fails the second time because it's already been deleted.I made a small change to
__init__to avoid adding the same key twice:And it appears to work, for this case and a few other simple sanity checks:
fix: ensure unique table indices when adding items to out-of-order ta…
fix: ensure unique table indices when adding items to out-of-order ta…
fix(deps): update dependency tomlkit to v0.13.3 (#343)