-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Setting a BaseSettings
field repeated times using different aliases in different settings sources results in ValidationError
#178
Comments
Hi @sujuka99, Thanks for reporting this 😄. The reasoning behind this is a bit complicated. So {'bar_env': 'env', 'bar_init': 'init'} However, the difficulty here is that then the following is occurring: from pydantic import AliasChoices, BaseModel, ConfigDict, Field
class FakeConfig(BaseModel):
bar: str = Field(validation_alias=AliasChoices('bar_env', 'bar_init'))
model_config = ConfigDict(extra='forbid')
fc = FakeConfig.model_validate({'bar_env': 'env', 'bar_init': 'init'}) However, the nature of Hopefully that explanation of the behavior makes some more sense. We're set up to prioritize fields specified in more highly prioritized sources, but not in the case of different aliases. If this is behavior that you'd like to see added, I suggest we move this to a feature request on the |
Hey @sydney-runkle, thanks for the thorough explanation! I would certainly like to see the behavior added 😄, should I move the request? Ultimately I would want to replicate what |
Thanks for the prompt response. After thinking about this more, I do think this is actually a bug. We guarantee that if an environment variable is specified in 2 locations (without an alias), we do prioritize and select appropriately, so I don't think the case should be any different when aliases are used. I'll move this issue to At the moment, you could set |
similar to #148 |
Hello, please tell me what I'm doing wrong, this code worked before update 2.1.0 -> 2.2.1
.env
|
@D1maD1m0nd probably related to #245 If you get |
Initial Checks
Description
I have 2 settings sources that refer to the same variable with different aliases and expect that the first one would be prioritized. Instead, the second time a settings source tries to set the variable under the different alias a
ValidationError
is thrown that says that the variable isextra
which it isn't.Pytest output
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: