Skip to content
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

Values printed in ValidationError stack traces for BaseSettings #256

Closed
sjking opened this issue Mar 14, 2024 · 2 comments
Closed

Values printed in ValidationError stack traces for BaseSettings #256

sjking opened this issue Mar 14, 2024 · 2 comments
Assignees

Comments

@sjking
Copy link

sjking commented Mar 14, 2024

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
@samuelcolvin
Copy link
Member

I think this is the same as pydantic/pydantic#7461

@samuelcolvin
Copy link
Member

but let's discuss an alternative.

@sjking sjking changed the title Secret values printed in ValidationError stack traces for BaseSettings Values printed in ValidationError stack traces for BaseSettings Mar 16, 2024
@sjking sjking closed this as completed Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants