You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The example given here doesn't actually change if you set nested_model_default_partial_update to False, so it's not clear to me what that flag actually does.
Playing around with it, it seems nested_model_default_partial_update only applies when a nested model has already been instantiated with non-default arguments. The documentation could be made clearer that when False, a new default instance of SubModel is created using only environment variables but when true, the existing SubModel instance is updated from the environment.
The code could be updated to, for example:
classSubModel(BaseModel):
val: int=0flag: bool=FalseclassSettings(BaseSettings):
model_config=SettingsConfigDict(env_nested_delimiter="__", nested_model_default_partial_update=True)
nested_model: SubModel=SubModel(val=1)
classSettingsFalse(BaseSettings):
model_config=SettingsConfigDict(env_nested_delimiter="__", nested_model_default_partial_update=False)
nested_model: SubModel=SubModel(val=1)
# Apply a partial update to the default object using environment variablesos.environ["NESTED_MODEL__FLAG"] ="True"print(Settings().model_dump())
print(SettingsFalse().model_dump())
The example given here doesn't actually change if you set
nested_model_default_partial_update
toFalse
, so it's not clear to me what that flag actually does.Playing around with it, it seems
nested_model_default_partial_update
only applies when a nested model has already been instantiated with non-default arguments. The documentation could be made clearer that when False, a new default instance of SubModel is created using only environment variables but when true, the existing SubModel instance is updated from the environment.The code could be updated to, for example:
output:
The text was updated successfully, but these errors were encountered: