Skip to content

Commit

Permalink
Merge branch 'main' into cli-kebab-case
Browse files Browse the repository at this point in the history
  • Loading branch information
kschwab committed Dec 3, 2024
2 parents 2ce7e24 + 0b3e73d commit 1e65224
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pydantic_settings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,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'),
)


Expand Down
12 changes: 7 additions & 5 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <bound method '
"BaseSettings.settings_customise_sources of <class 'pydantic_settings.main.BaseSettings'>> "
'of protected namespace "settings_".'
'of protected namespace "settings_customise_sources".'
),
):

Expand Down

0 comments on commit 1e65224

Please sign in to comment.