Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same -1 index error on newest version #332

Closed
macabrus opened this issue Feb 16, 2024 · 1 comment · Fixed by #335
Closed

Same -1 index error on newest version #332

macabrus opened this issue Feb 16, 2024 · 1 comment · Fixed by #335
Assignees

Comments

@macabrus
Copy link

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

@macabrus
Copy link
Author

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.

@frostming frostming self-assigned this Feb 27, 2024
frostming added a commit that referenced this issue Feb 27, 2024
Fixes #332

Signed-off-by: Frost Ming <me@frostming.com>
frostming added a commit that referenced this issue Feb 27, 2024
…rost Ming <me@frostming.com>

* fix: -1 index error when setting dotted key
Fixes #332

Signed-off-by: Frost Ming <me@frostming.com>
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 a pull request may close this issue.

2 participants