Skip to content
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

deprecation warning for case_insensitive on BaseSettings config #885

Merged
merged 1 commit into from Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/885-samuelcolvin.md
@@ -0,0 +1 @@
deprecation warning for `case_insensitive` on `BaseSettings` config
8 changes: 8 additions & 0 deletions pydantic/main.py
Expand Up @@ -118,6 +118,14 @@ def prepare_config(config: Type[BaseConfig], cls_name: str) -> None:
)
config.allow_population_by_field_name = config.allow_population_by_alias # type: ignore

if hasattr(config, 'case_insensitive') and any('BaseSettings.Config' in c.__qualname__ for c in config.__mro__):
warnings.warn(
f'{cls_name}: "case_insensitive" is deprecated on BaseSettings config and replaced by '
f'"case_sensitive" (default False)',
DeprecationWarning,
)
config.case_sensitive = not config.case_insensitive # type: ignore


def is_valid_field(name: str) -> bool:
if not name.startswith('_'):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_settings.py
Expand Up @@ -252,6 +252,22 @@ class Config:
assert exc_info.value.errors() == [{'loc': ('foo',), 'msg': 'field required', 'type': 'value_error.missing'}]


def test_case_insensitive(monkeypatch):
class Settings1(BaseSettings):
foo: str

with pytest.warns(DeprecationWarning, match='Settings2: "case_insensitive" is deprecated on BaseSettings'):

class Settings2(BaseSettings):
foo: str

class Config:
case_insensitive = False

assert Settings1.__config__.case_sensitive is False
assert Settings2.__config__.case_sensitive is True


def test_nested_dataclass(env):
@dataclasses.dataclass
class MyDataclass:
Expand Down