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

keygroup with empty name is allowed in particular formatting, but not in what toml.dump creates. #413

Open
spokeydokeys opened this issue Mar 8, 2023 · 1 comment

Comments

@spokeydokeys
Copy link

spokeydokeys commented Mar 8, 2023

Description

When using toml to store a logging dictConfig, I want to store a keygroup with a name of "" to reference the root logger. For example:

[logging]
version = 1

[logging.loggers]
"" = {level='NOTSET', handlers=[]}
"action" = {level='DEBUG', handlers=['file']}

[logging.handlers.file]
class = 'logging.handlers.RotatingFileHandler'
formatter = 'full'
level = 'DEBUG'
filename = 'action.log'
maxBytes = 52428800  # 50 * 2**20 (50 MB)
backupCount = 5

[logging.formatters.full]
format='%(asctime)s [%(levelname)s] %(name)s:%(filename)s:%(lineno)d - %(message)s'

The above works perfectly. toml.load of the above code results in the dictionary I expect. However, if this written from a dict using toml.dump, the resulting toml has a the loggers group decomposed into

[logging.loggers.""]
level='NOTSET'
handlers=[]

[logging.logger.action]
level='DEBUG'
handlers=['file']

Loading this with toml.load results in the error TomlDecodeError: Can't have a keygroup with an empty name

I store my default configurations in a pydantic BaseModel that is then dumped to dict and finally written to a toml file on installation. The above means that I can't use toml as a config format for my logging configuration as I have to go in and change the second version to the first for it to work. Ultimately I'll have to host it in another configuration format, which is unfortunate.

Request:

Either:

  1. Allow the empty keygroup
  2. Have toml.dump generate a file that can be read using toml.load
@spokeydokeys
Copy link
Author

tomlkit is tolerant of this issue.

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

No branches or pull requests

1 participant