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

Empty key-value pair in a list is not dumped correctly #364

Open
vlandeiro opened this issue May 25, 2021 · 0 comments
Open

Empty key-value pair in a list is not dumped correctly #364

vlandeiro opened this issue May 25, 2021 · 0 comments
Labels
component: encoder Related to serialising in `toml.dump` syntax: arrays Related to arrays syntax: inline table Related to inline tables type: bug A confirmed bug or unintended behavior

Comments

@vlandeiro
Copy link

vlandeiro commented May 25, 2021

Using the latest commit on master (3f637db at this time), here is a minimal example to reproduce the issue I'm encountering:

>>> import toml
>>> broken = {"foo": [{"bar": {}, "moot": {"a": 1}}]}
>>> broken
{'foo': [{'bar': {}, 'moot': {'a': 1}}]}
>>> print(toml.dumps(broken))
[[foo]]

[foo.moot]
a = 1
>>> toml.loads(toml.dumps(broken))
{'foo': [{'moot': {'a': 1}}]}
>>> toml.loads(toml.dumps(broken)) == broken
False

Note how the bar key disappears when dumping the dictionary to TOML, leading to data loss when passing the original data through a dumps/loads round trip.

The expected behavior is that toml.dumps(broken) returns the following TOML that can then be parsed to retrieve the original data.

[[foo]]
[foo.bar]

[foo.moot]
a = 1

Another thing to note is that this is only an issue when the key-value pair is part of a list. For instance, the following example behaves as expected:

>>> working = {"foo": {"bar": {}}}
>>> toml.loads(toml.dumps(working))
{'foo': {'bar': {}}}
>>> toml.loads(toml.dumps(working)) == working
True
Aplet123 added a commit to Aplet123/toml that referenced this issue Jun 23, 2021
@pradyunsg pradyunsg added component: encoder Related to serialising in `toml.dump` type: bug A confirmed bug or unintended behavior syntax: inline table Related to inline tables syntax: arrays Related to arrays labels Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: encoder Related to serialising in `toml.dump` syntax: arrays Related to arrays syntax: inline table Related to inline tables type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants