-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
falls back to env vars without prefix
#441
Comments
I'm confused about env_prefix. When I use env_prefix, the original env var gets ignored. It will only load an env var if it it matches the name with the env_prefix. |
Yes, it works when there an env var exists with the prefix. But I think it should stay empty if it does not find the env var + prefix as opposed to fall back to an env var without the prefix.
|
Thanks! I thought that setting env_prefix acted like an alias, such that in your example, either I'm currently struggling with pydantic as well, but it seems like we're observing different behavior. In my use case, I was expecting the env var to get loaded from the raw variable or the variable name with the env_prefix (in other words, like I described above, where it would work like an alias). However, it ONLY works for the variable name with the env_prefix (the raw variable name doesn't work, unlike alias behavior). @hofrob, does this sounds like the opposite problem that you're having?
|
Using my example from #437: https://github.com/hofrob/pydantic-settings-env-prefix
If you
uv run hello
the result is:This value is coming from the first line in
.env
:HELLO=ABC
I don't think the intention of
env_prefix
is to just fall back to whatever env var it can find that matches the variable without the prefix. If you have nested or complex settings with multiple API keys managed via differentenv_prefix
values, you'll not want to use an API key with the wrong service. I'd consider this API key compromised.See also this comment: #437 (comment)
The text was updated successfully, but these errors were encountered: