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

Tomlkit 0.11.2 issue parsing array with comment when later subsections are present #222

Closed
airstandley opened this issue Aug 9, 2022 · 0 comments · Fixed by #221
Closed

Comments

@airstandley
Copy link

airstandley commented Aug 9, 2022

Poetry recently started failing to parse one of our project's pyproject.toml files, and we tracked it down to the bump from tomlkit 0.11.1 to 0.11.2.

Specifically 0.11.1 succeed in parsing the file while 0.11.2 fails causes poetry to throw the parsing error
[packages.0] None is not of type 'object'.

Investigating further showed that the issue was that commented lines in the array were being parsed as array items.

It took quite a big of testing to figure out exactly what scenario caused the array with comments to be parsed incorrectly. Specifically it's when there is another subsection later in the file.

Reproduced with the following toy example:

from tomlkit import parse
content = """
[section.subsection]
my_array = [
   # This is a comment
   { item = 1 }
]

[section.othersubsection]
key = "value"
"""
parse(content)

{'section': {'subsection': {'my_array': [None, {'item': 1}]}, 'othersubsection': {'key': 'value'}}}

Note that order matters, the following parses correctly

content ="""
[section.subsection]
key = "value"

[section.othersubsection]
array = [
  # Comment
  { item = 1 }
]
 """
@airstandley airstandley changed the title Tomlkit 0.11.2 issue parsing array with comment when subsections are present Tomlkit 0.11.2 issue parsing array with comment when later subsections are present Aug 9, 2022
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.

1 participant