Skip to content

Conversation

d15ky
Copy link
Contributor

@d15ky d15ky commented Apr 23, 2025

Fix case-insensitive handling of nested aliases in EnvironmentSettingsSource

This PR fixes a bug in EnvironmentSettingsSource where nested models with validation aliases were not correctly populated from environment variables when case_sensitive=False.

Previously, case-insensitive matching did not take aliases into account in nested contexts, resulting in missing values. This fix ensures correct resolution in such cases.

All tests pass, linting is clean, and a dedicated test has been added to validate the fix without modifying existing test coverage. Code style and structure were followed closely to match the existing patterns in both implementation and testing.

Example

from pydantic import BaseModel, Field
from pydantic_settings import BaseSettings

class Inner(BaseModel):
    some_value: str = Field(..., alias="MyKey")

class Outer(BaseSettings):
    inner: Inner

# With case_sensitive=False, 'MYKEY' will correctly map to 'some_value'

@hramezani hramezani merged commit 212784c into pydantic:main Apr 23, 2025
18 checks passed
@hramezani
Copy link
Member

Thanks @d15ky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants