lincolnloop / goodconf

Transparently load variables from environment or JSON/YAML/TOML file.
MIT License
129 stars 6 forks source link

repeating config.load() fails to read default_files #48

Open roharvey opened 2 months ago

roharvey commented 2 months ago

If you happen to call config.load() twice, the latter fails to read from default_files. This leads to difficult to troubleshoot issues like:

pydantic_core._pydantic_core.ValidationError: 1 validation error for AppConfig
SECRET_KEY
  Field required [type=missing, input_value={}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.8/v/missing

This probably is avoidable by very reasonably saying that we shouldn't be calling config.load() twice. However the docs suggest using config.django_manage() which itself calls config.load(), so in that case at least it is unavoidable.

It looks like the method to check for files loaded data in version 5.0 should be updated.

ipmb commented 2 months ago

ruamel.yaml is only loaded if a yaml file has been specified as the config file. It is optional in the sense that, if you don't want to load yaml files, you don't need it.

https://github.com/lincolnloop/goodconf/blob/4b32897f181f5cf11f39682bf961fc885498c5bd/goodconf/__init__.py#L68-L69

roharvey commented 2 months ago

Gotcha! I'll update the ticket