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
Given a .env file which includes an environment variable without a prefixed namespace, but the settings config is configured to use a prefix, it attempts to load the non-prefixed value, then fails to interpret the JSON structure anyway, saying the input type is a string:
1 validation error for Settingsmy_model Input should be a valid dictionary or instance of MyModel [type=model_type, input_value='{"a":1}', input_type=str] For further information visit https://errors.pydantic.dev/2.10/v/model_type
I would expect in this case that it would simply resolve to None - the non-prefixed env variable should be ignored.
Only one scenario in the env_file/env_prefix matrix is misbehaving (env_file="env-no-prefix.env", env_prefix="PREFIX_") - the others are working as expected:
$ python -m appenv_file=None, env_prefix=None, settings=my_model=Noneenv_file=None, env_prefix=PREFIX_, settings=my_model=Noneenv_file=env-no-prefix.env, env_prefix=None, settings=my_model=MyModel(a=1)env_file=env-no-prefix.env, env_prefix=PREFIX_, 1 validation error for Settingsmy_model Input should be a valid dictionary or instance of MyModel [type=model_type, input_value='{"a":1}', input_type=str] For further information visit https://errors.pydantic.dev/2.10/v/model_typeenv_file=env-prefix-only.env, env_prefix=None, settings=my_model=Noneenv_file=env-prefix-only.env, env_prefix=PREFIX_, settings=my_model=MyModel(a=4)env_file=env-prefix-and-no-prefix.env, env_prefix=None, settings=my_model=MyModel(a=2)env_file=env-prefix-and-no-prefix.env, env_prefix=PREFIX_, settings=my_model=MyModel(a=3)
Seems related to #441 but more specific, since it has to do with interpreting a complex type.
Given a
.env
file which includes an environment variable without a prefixed namespace, but the settings config is configured to use a prefix, it attempts to load the non-prefixed value, then fails to interpret the JSON structure anyway, saying the input type is a string:I would expect in this case that it would simply resolve to None - the non-prefixed env variable should be ignored.
Using pydantic-settings 2.8.1 on Python 3.10
To reproduce:
Only one scenario in the
env_file
/env_prefix
matrix is misbehaving (env_file="env-no-prefix.env", env_prefix="PREFIX_"
) - the others are working as expected:Seems related to #441 but more specific, since it has to do with interpreting a complex type.
Similar to #196
The text was updated successfully, but these errors were encountered: