Skip to content

Commit 0b3e73d

Browse files
authored
Relax default protected_namespaces (#483)
1 parent 3f831e9 commit 0b3e73d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

pydantic_settings/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def _settings_build_values(
424424
yaml_file_encoding=None,
425425
toml_file=None,
426426
secrets_dir=None,
427-
protected_namespaces=('model_', 'settings_'),
427+
protected_namespaces=('model_validate', 'model_dump', 'settings_customise_sources'),
428428
)
429429

430430

tests/test_settings.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -2202,26 +2202,28 @@ class Settings(BaseSettings):
22022202
def test_protected_namespace_defaults():
22032203
# pydantic default
22042204
with pytest.warns(
2205-
UserWarning, match='Field "model_prefixed_field" in Model has conflict with protected namespace "model_"'
2205+
UserWarning,
2206+
match='Field "model_dump_prefixed_field" in Model has conflict with protected namespace "model_dump"',
22062207
):
22072208

22082209
class Model(BaseSettings):
2209-
model_prefixed_field: str
2210+
model_dump_prefixed_field: str
22102211

22112212
# pydantic-settings default
22122213
with pytest.warns(
2213-
UserWarning, match='Field "settings_prefixed_field" in Model1 has conflict with protected namespace "settings_"'
2214+
UserWarning,
2215+
match='Field "settings_customise_sources_prefixed_field" in Model1 has conflict with protected namespace "settings_customise_sources"',
22142216
):
22152217

22162218
class Model1(BaseSettings):
2217-
settings_prefixed_field: str
2219+
settings_customise_sources_prefixed_field: str
22182220

22192221
with pytest.raises(
22202222
NameError,
22212223
match=(
22222224
'Field "settings_customise_sources" conflicts with member <bound method '
22232225
"BaseSettings.settings_customise_sources of <class 'pydantic_settings.main.BaseSettings'>> "
2224-
'of protected namespace "settings_".'
2226+
'of protected namespace "settings_customise_sources".'
22252227
),
22262228
):
22272229

0 commit comments

Comments
 (0)