Skip to content

0.15.0 serializes invalid TOML when appending to a parsed inline table #476

Closed

Description

@cyliu0

Summary

In tomlkit 0.15.0, appending a new key to a parsed inline table that already contains multiple key/value pairs can produce invalid TOML: the newly appended key is serialized without a comma separator before it.

This appears to be a regression from 0.14.0.

Reproducer

import tomlkit

print(tomlkit.__version__)

doc = tomlkit.parse('x = { a = 1, b = 2 }\n')
doc['x']['c'] = 3

out = doc.as_string()
print(out, end='')

tomlkit.parse(out)

Actual behavior on 0.15.0

0.15.0
x = { a = 1, b = 2 c = 3}
Traceback ...
tomlkit.exceptions.UnexpectedCharError: Unexpected character: 'c' at line 1 col 19

The serialized TOML is invalid because the inline table is missing a comma between b = 2 and c = 3.

Expected behavior

as_string() should produce valid TOML, for example:

x = { a = 1, b = 2, c = 3}

The same reproducer works on 0.14.0:

0.14.0
x = { a = 1, b = 2, c = 3}

Environment

  • Python: 3.13.2
  • tomlkit: 0.15.0
  • Last known good version tested: 0.14.0

Notes

This only seems to happen when mutating a parsed inline table with multiple existing entries. Creating/replacing an inline table from scratch still serializes commas correctly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions