Skip to content

Parsing Secret[] values error #475

@zoola969

Description

@zoola969

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 working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions