-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
env_prefix ignored if extra=allow #474
Comments
Thanks @iAnanich for reporting this. Yeah, it it an expected behavior and we already documented it:
|
That removes usecase that I quite liked: having a bunch of Models read with different sets of variables, each with their own prefix, possibly nested, while allowing for extra fields to be added without disturbing. That note makes it seem like |
Agree, probably it is not clear. |
I believe this change is a consequence of #218 and #221 nuance of allowing undeclared variables with prefix or just ignoring them was lost. In my head 3 flags were enough:
I haven't encountered other scenarios, but there might be a case for raising an error if there is an undeclared environment variable that matches the prefix, while ignoring undeclared variables that do not match the prefix. A potential solution could be a strict_env_prefix flag: when set to true, the model would only validate and get affected by environment variables that match the prefix. Otherwise, even using forbid wouldn't apply to variables that don't match. However, this seems unnecessary since the env_prefix is already defined - if all environment variables are required to have it, what is the purpose of having the flag? |
The reason that we collect all the values in |
Problem: if model has both
extra="allow"
andenv_prefix
set, then model will have all envvars regardless of prefix, essentially ignorringenv_prefix
config.Expected behavior: fields that match
env_prefix
can be added into model, even if they are not declared.Noticed that it changed when upgraded, remember that in 2.1 it was clsoer to that, but also actually didn't include undeclared vars from .env . But having undeclared vars in .env that is shared between multiple nested settings files broke my code :)
Example code:
respective
.env
to test:So latest main gives this output:
and
v2.1.0
gives this:The text was updated successfully, but these errors were encountered: