Skip to content

Release 2.2 breaks enviroment prefix #245

@dleifeld

Description

@dleifeld

This .envs file:

TESTING=TRUE

CONNECTION_ADDRESS="example.com"
CONNECTION_PORT=443

worked in Pydantic Settings 2.1 with this python code without problems:

from pydantic_settings import BaseSettings, SettingsConfigDict

class ConnectionSettings(BaseSettings):
    model_config = SettingsConfigDict(env_prefix='connection_', env_file='.envs')

    address: str
    port: int


def get_conn_params() -> ConnectionSettings:
    settings = ConnectionSettings()   # pyright: ignore
    print(settings)

    return settings

# if executed as a script
if __name__ == "__main__":
    get_conn_params()

But in Pydantic Settings 2.2 this error is thrown:

pydantic_core._pydantic_core.ValidationError: 1 validation error for ConnectionSettings
testing
  Extra inputs are not permitted [type=extra_forbidden, input_value='TRUE', input_type=str]

In my opinion the setting env_prefix should imply, that inputs without this prefix are ignored.
I am not sure why else a prefix should be used.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions