From 2e32d23164720a3a9461f0b64c61ee0e1d3ee118 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Tue, 26 Nov 2024 12:30:00 +0100 Subject: [PATCH] Relax default protected_namespaces --- pydantic_settings/main.py | 2 +- tests/test_settings.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pydantic_settings/main.py b/pydantic_settings/main.py index 723d6d5..4903ffc 100644 --- a/pydantic_settings/main.py +++ b/pydantic_settings/main.py @@ -424,7 +424,7 @@ def _settings_build_values( yaml_file_encoding=None, toml_file=None, secrets_dir=None, - protected_namespaces=('model_', 'settings_'), + protected_namespaces=('model_validate', 'model_dump', 'settings_customise_sources'), ) diff --git a/tests/test_settings.py b/tests/test_settings.py index 2179817..143b285 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -2202,26 +2202,28 @@ class Settings(BaseSettings): def test_protected_namespace_defaults(): # pydantic default with pytest.warns( - UserWarning, match='Field "model_prefixed_field" in Model has conflict with protected namespace "model_"' + UserWarning, + match='Field "model_dump_prefixed_field" in Model has conflict with protected namespace "model_dump"', ): class Model(BaseSettings): - model_prefixed_field: str + model_dump_prefixed_field: str # pydantic-settings default with pytest.warns( - UserWarning, match='Field "settings_prefixed_field" in Model1 has conflict with protected namespace "settings_"' + UserWarning, + match='Field "settings_customise_sources_prefixed_field" in Model1 has conflict with protected namespace "settings_customise_sources"', ): class Model1(BaseSettings): - settings_prefixed_field: str + settings_customise_sources_prefixed_field: str with pytest.raises( NameError, match=( 'Field "settings_customise_sources" conflicts with member > " - 'of protected namespace "settings_".' + 'of protected namespace "settings_customise_sources".' ), ):