Toml file badly processed if it contains table aka. section in .ini files (name in brackets [])
Hi,
confz is very good tool, started to use right now, and found the following:
I created the following config
# config.py
import os
from pathlib import Path
from confz import ConfZ, ConfZFileSource
from pydantic import AnyUrl
my_script_path = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
class APIConfig(ConfZ):
login_page: AnyUrl = "https://abc.com/login"
CONFIG_SOURCES = ConfZFileSource(
folder=Path(my_script_path),
file_from_env='TESTING_API_CONFIG',
optional=True, # because default is added above
)
# config_some_environment.toml
[APIConfig]
login_page = "https://abc.com/login----from_file_just_to_see_the_diff_debug"
# environment variable added
TESTING_API_CONFIG=config_some_environment.toml
and the login_page value was the default one. Started to debug it and found, that Toml interpreter creates nested dicts if the file contains table [APIConfig]:
{"APIConfig": {"login_page": "https://abc.com/login----from_file_just_to_see_the_diff_debug"}}
and found a call in confz.py line 50:
cls.confz_instance = super().__call__(**config)
perhaps this is the point where the nested dict makes the issue. Unfortunately PyCharm did not show the source of super()... so finished debugging here.
Perhaps this relates a little bit to issue #14
BR, George
Hi George, thanks for your request!
You are right, this way it would only work if your APIConfig has a field which would again be called "APIConfig", and there then a field "login_page". I would have said that this is the intended behaviour. I'm not so familiar with toml parsing, what if you remove the [APIConfig] tag and only have "login_page" in your toml?
Closing this issue due to inactivity. Please re-open if you still consider the current behaviour a bug.
Hi @silvanmelchior,
if I remove the [APIConfig]
it works well, but in this case the file is not a toml file, just a text file with key value pairs.
The APIConfig -> APIConfig -> login_page syntax is quite weird, I think. At least it should be documented in the current version.
And solving this would solve the issue #14 too. One file could contain more config parts in different sections
BR, George
Closing this issue due to inactivity. Please re-open if you still consider the current behaviour a bug.
Yes, I think it should be reopened, but only repo owner / collaborator can reopen the issue
I flag it as a possible improvement for the documentation, so it's more obvious that the toml file acts as the root of the config class and possible sections wihtin the toml file refer to sub-configs. Please also see the test file "https://github.com/Zuehlke/ConfZ/blob/main/tests/assets/config.toml" for more options.