-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
is ignored if pydantic_settings finds an env var without prefix
#437
Comments
Thanks @hofrob for reporting this bug. I will prepare a fix for it. |
I checked the following:
All show the expected results! bug? remove the prefixed variableRemoving the prefixed variable falls back to the other variable which I think is a problem. Potentially even a security risk. bug?
|
Thanks @hofrob for quick feedback! |
Should I create separate issues for the other ones? Are they not considered bugs? Just using a different env var when it's explicitly configured to use a prefix sounds like an actual problem to me. |
This happens because the dotenv settings source must consider the extra envs provided in the dotenv file because dotenv settings sources cares about So, |
Initial Checks
Description
When using
env_prefix
in amodel_config
, pydantic_settings will still load values from env vars that do not use the given prefix. Values from env vars without the prefix even have higher priority.Example repo: https://github.com/hofrob/pydantic-settings-env-prefix
uv run hello
HELLO=ABC
should just be ignored in my opinion (can't find anything definitive in the docs).Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: