Skip to content

Settings from .env file not overriding the default #652

Open
@rsamf

Description

@rsamf

I have my settings class configured to load environment variables from a .env file, but the values from the .env file aren't overriding the default. I have a minimal example below:

from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict

class Settings(BaseSettings):
    """Application settings with environment variable support."""
    model_config = SettingsConfigDict(
        env_file='.env', 
        env_file_encoding='utf-8',
    )
    
    # Application settings
    app_name: str = Field(default="foo", alias="APP_NAME")

settings = Settings()
print(settings.app_name) # always prints "foo"

In my .env file:

APP_NAME="bar"

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions