-
-
Notifications
You must be signed in to change notification settings - Fork 82
Fix for case-insensitive alias matching in InitSettingsSource
#609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@Shindora, you've added two tests to the PR, but both pass without your change in |
@Shindora, the 'test_case_sensitive ' test passes without your change in |
This is the only failing case class CaseInsensitiveSettings(BaseSettings):
foo: str = Field(..., alias='FOO')
model_config = SettingsConfigDict(case_sensitive=False, extra='allow')
# Test case-insensitive with extra field
monkeypatch.setattr(os, 'environ', value={})
init_kwargs = {'Foo': 'foo_value', 'extra_field': 'extra_value'}
settings = CaseInsensitiveSettings(**init_kwargs)
assert settings.foo == 'foo_value'
assert settings.__pydantic_extra__ == {'extra_field': 'extra_value'} Please revert your change in cc @kschwab |
reverted ! I add the new test case to cover my adjustment |
Thanks @Shindora for the update. Actually, What do you think @kschwab? |
Issue
When using case-insensitive settings with aliases, the InitSettingsSource wasn't correctly matching field aliases in a case-insensitive manner due to not considering case sensitivity when obtaining alias names.
Changes
Modified the
__init__
method ofInitSettingsSource
to pass the case_sensitive parameter to get_alias_names() when generating match aliasesNow properly creates two sets of aliases:
Add unittest
test_init_settings_source_extra_fields_case_sensitive