-
-
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
Extra.Forbid is not applied when using BaseSettings with Config.env_file defined #11
Comments
Good catch, thanks for reporting. Realistically this won't be changed in pydantic v1.10, but we should make sure it's fixed in pydantic V2 where settings will become a separate package which uses |
@samuelcolvin Is it really a bug? It seems we loop over settings fields and collect the value for the fields from file or environment variables. So, we won't get the extra value provided in the file. Am I wrong? |
I haven't actually tried it. We need to check the current behaviour then decide if it's correct or needs changing. |
Currently we loop over fields and collect the values. If we are going to change the behavior, we need to collect the envs and then initialize the model. Then the default behavior(collect envs from environment without prefix and dotenv file) will be tricky because if we define a model with a field named |
Ye, extra behaviour should definitely always be "ignore" for env vars, but for other sources like dotenv, I can see the value in allowing "forbid" or "include". |
OK, that needs to be changed and documented |
It's me who thanks you for all your amazing contributions to the python ecosystem ! |
Initial Checks
Description
Reading the documentation and as BaseSettings inherits from BaseModel it'd be expected to have
Config.extra
parameters working whenConfig.env_file
is defined.It appears that without Config.env files it works as expected, but when it comes from env_files the extra config is ignored.
If this is expected I can make a PR to make the documentation more explicit on this specific point.
Example Code
Python, Pydantic & OS Version
Affected Components
.dict()
and.json()
construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: