-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Is EnvSettingsSource
's behavior intentional or bug?
#258
Comments
Thanks @qkrwoghk15 for reporting this. This is the intended behavior. |
Oh, Thanks @hramezani for your response. As you say, when capital letters exist in the
I would appreciate it if you could check the code results below to make sure my understanding is correct.
class MyModel(BaseModel):
a: int = Field(alias="a")
class MySettings(BaseSettings):
uid: str
name: str
inner: MyModel
model_config = SettingsConfigDict(env_nested_delimiter="__", case_sensitive=False)
test("inner__a")
# uid='uid' name='name' inner=MyModel(a=3)
test("inner__A")
# uid='uid' name='name' inner=MyModel(a=3)
class MyModel(BaseModel):
a: int = Field(alias="A")
class MySettings(BaseSettings):
uid: str
name: str
inner: MyModel
model_config = SettingsConfigDict(env_nested_delimiter="__", case_sensitive=False)
test("inner__a")
"""
1 validation error for MySettings
inner.A
Field required [type=missing, input_value={'a': '3'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.6/v/missing
"""
test("inner__A")
"""
1 validation error for MySettings
inner.A
Field required [type=missing, input_value={'a': '3'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.6/v/missing
""" I can infer the relationship between
but it was difficult to infer this dependence between |
@qkrwoghk15 Probably, making all envs lowercase at the beginning is not a good approach but nested model parsing in very complicated and I am afraid of changing it needs a lot of changes. feel free to ask here if you don't understand it clearly or have more questions. |
Thank you so much for sharing your opinions freely @hramezani . I just thought it would be good to have a clear definition of the relationship between In general, in below is an example. class MySettings(BaseSettings):
name: str = Field(alias="Name")
model_config = SettingsConfigDict(case_sensitive=False)
test(MySettings, "name") # name = "..."
test(MySettings, "Name") # name = "..."
test(MySettings, "NamE") # name = "..." and if class MySettings(BaseSettings):
name: str = Field(alias="Name")
model_config = SettingsConfigDict(case_sensitive=True)
test(MySettings, "name") # 1 validation error for MySettings ...
test(MySettings, "Name") # name = "..."
test(MySettings, "NamE") # 1 validation error for MySettings ... However, the interaction between I am also afraid because it is not clear to what extent this change will affect me, and I believe that such usage examples (capitalizing the nested model's I have not yet looked into where the nested model is processed in pydantic BaseModel's Let's think about some more good ways :) |
Not sure how you would use the validation context here? I would like to work on this part and improve inner model value extraction but unfortunately, I can't say when it will happen. As I mentioned before the inner model value extraction implementation is complex and I am afraid we introduce a breaking change by changing this part |
Sorry for the delay in replying because of personal schedule. I often use What I thought was temporary and also a bad idea because I don't know where and how to use ruff.
I don't think this issue is urgent |
Hi, I was using the dotenv related settings in pydantic BaseSettings and found something weird.
Nested 'BaseModel' is used for 'BaseSettings', and the alias of the inner model operate dependently on each other as it is set with 'case_sensitive' in the outer model.
Below is an example code for the above situation.
when outer Model's
case_sensitive
isFalse
,then
but when outer Model's
case_sensitive
isTrue
,then the result is below.
I think it's a movement that comes from this line
Is this an intended action or is it a bug?
Thanks for reading my long issue
The text was updated successfully, but these errors were encountered: