-
-
Notifications
You must be signed in to change notification settings - Fork 108
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
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.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working