From d21c82a68b8dc2e94027f27401f8422c87847eb1 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Fri, 2 Jun 2023 14:14:53 +0330 Subject: [PATCH] Update pydantic to 2.0b1 (#64) --- pydantic_settings/main.py | 1 + pyproject.toml | 2 +- requirements/pyproject.txt | 4 ++-- tests/test_settings.py | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pydantic_settings/main.py b/pydantic_settings/main.py index c5255d12..88478f16 100644 --- a/pydantic_settings/main.py +++ b/pydantic_settings/main.py @@ -127,4 +127,5 @@ def _settings_build_values( env_file_encoding=None, env_nested_delimiter=None, secrets_dir=None, + protected_namespaces=('model_', 'settings_'), ) diff --git a/pyproject.toml b/pyproject.toml index 99b42538..9ec4ea86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ classifiers = [ ] requires-python = '>=3.7' dependencies = [ - 'pydantic>=2.0a4', + 'pydantic>=2.0b1', 'python-dotenv>=0.21.0', ] dynamic = ['version'] diff --git a/requirements/pyproject.txt b/requirements/pyproject.txt index 2ae6426b..f893da0e 100644 --- a/requirements/pyproject.txt +++ b/requirements/pyproject.txt @@ -6,9 +6,9 @@ # annotated-types==0.4.0 # via pydantic -pydantic==2.0a4 +pydantic==2.0b1 # via pydantic-settings (pyproject.toml) -pydantic-core==0.30.0 +pydantic-core==0.38.0 # via pydantic python-dotenv==0.21.1 # via pydantic-settings (pyproject.toml) diff --git a/tests/test_settings.py b/tests/test_settings.py index b4ea8fe6..683f12b4 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1614,3 +1614,19 @@ class Settings(BaseSettings): assert s.v0 == 'v0' assert s.sub_model.v1 == 'v1' assert s.sub_model.v2 == b'v2' + + +def test_protected_namespace_defaults(): + # pydantic default + with pytest.raises(NameError, match='Field "model_prefixed_field" has conflict with protected namespace "model_"'): + + class Model(BaseSettings): + model_prefixed_field: str + + # pydantic-settings default + with pytest.raises( + NameError, match='Field "settings_prefixed_field" has conflict with protected namespace "settings_"' + ): + + class Model1(BaseSettings): + settings_prefixed_field: str