I have some value stored in an environment variable that I am reading into a custom BaseSettings subclass. I am using a Field of type SecretStr, with repr=False for this value in the model class. If there is a validation error, and the first value is present, but some other value in the model is missing, then the stack trace includes the value that was present. Should this be default behaviour? Please see below for a reproducible example:
from pydantic import Field, SecretStr
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
first_value: SecretStr = Field(validation_alias="MY_FIRST_VALUE", repr=False)
other_value: str = Field(validation_alias="MY_OTHER_VALUE")
settings = Settings()
$ export MY_FIRST_VALUE=test123
$ python main.py
...
pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings
other_value
Field required [type=missing, input_value={'MY_FIRST_VALUE: 'test123'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.6/v/missing
I have some value stored in an environment variable that I am reading into a custom
BaseSettings
subclass. I am using aField
of typeSecretStr
, withrepr=False
for this value in the model class. If there is a validation error, and the first value is present, but some other value in the model is missing, then the stack trace includes the value that was present. Should this be default behaviour? Please see below for a reproducible example: