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

Parsing Secret[] values error #475

Closed
zoola969 opened this issue Nov 11, 2024 · 3 comments · Fixed by #478
Closed

Parsing Secret[] values error #475

zoola969 opened this issue Nov 11, 2024 · 3 comments · Fixed by #478
Assignees
Labels
bug Something isn't working

Comments

@zoola969
Copy link

When attempting to parse an environment variable to a Secret[], the pydantic-settings module raises an error.

How to reproduce:

import os

from pydantic import PostgresDsn, SecretStr, Secret
from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    DSN1: SecretStr
    DSN2: PostgresDsn
    DSN3: Secret[PostgresDsn]


os.environ["DSN1"] = "postgresql://user:password@localhost/db"
os.environ["DSN2"] = "postgresql://user:password@localhost/db"
os.environ["DSN3"] = "postgresql://user:password@localhost/db"

settings = Settings()

Expected behaviour:
DSN3 successfully parsed into Secret[PostgresDsn] type

Actual behaviour:
pydantic_settings.sources.SettingsError: error parsing value for field "DSN3" from source "EnvSettingsSource"

Additional info:
As I understood from the stacktrace, DSN3 is marked as a complex field, and pydantic-settings attempts to parse it from JSON.

@hramezani
Copy link
Member

Thanks @zoola969 for reporting this issue.

I will investigate the problem and will prepare a fix.

@hramezani hramezani added bug Something isn't working and removed unconfirmed labels Nov 12, 2024
@hramezani
Copy link
Member

@zoola969 I created #478 to fix the problem.

Could you please confirm?

@zoola969
Copy link
Author

@hramezani checked on your branch, works good, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants