python-poetry/tomlkit

Same -1 index error on newest version

macabrus opened this issue · 1 comments

Previous issue: #317

This is the issue i get only when modifying multiple sections of a document.
As per my last issue, which seemingly was resolved, I have once again found same error on newest version:

import tomlkit

doc = tomlkit.parse('''
[a]
    [a.b]
    b = 0
    
[b]
    [b.b]
    q = '123'
    c = '43543'
''')

for section in ('a', 'b'):
    for label, obj in doc[section].items():
        obj[tomlkit.key(['a', 'b'])] = 'test1'

for section in ('a', 'b'):
    for label, obj in doc[section].items():
        obj[tomlkit.key(['a', 'c'])] = 'test2'

print(tomlkit.dumps(doc))

throws:

...
self._table_keys[-1] != current_body_element[0]
    ~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range

I can confirm that issue does not occur if I serialize and deserialize in between top level for loops:

...
doc = tomlkit.parse(tomlkit.dumps(doc))
...

which leads me to believe this is internal implementation issue on how node changes are applied.

For now, I will use workaround by intermediary serialization.