diff --git a/changes/926-retnikt.md b/changes/926-retnikt.md new file mode 100644 index 0000000..2152ea6 --- /dev/null +++ b/changes/926-retnikt.md @@ -0,0 +1 @@ +Clarify usage of `remove_untouched`, improve error message for types with no validators. diff --git a/docs/usage/model_config.md b/docs/usage/model_config.md index 4933504..6fb55d7 100644 --- a/docs/usage/model_config.md +++ b/docs/usage/model_config.md @@ -62,8 +62,8 @@ Options: : a callable that takes a field name and returns an alias for it **`keep_untouched`** -: a tuple of types (e.g. descriptors) that should not be changed during model creation and will not be - included in the model schemas +: a tuple of types (e.g. descriptors) for a model's default values that should not be changed during model creation and will +not be included in the model schemas. **Note**: this means that attributes on the model with *defaults of this type*, not *annotations of this type*, will be left alone. **`schema_extra`** : a `dict` used to extend/update the generated JSON Schema diff --git a/pydantic/validators.py b/pydantic/validators.py index ae1365c..2ccefaf 100644 --- a/pydantic/validators.py +++ b/pydantic/validators.py @@ -568,9 +568,7 @@ def find_validators( # noqa: C901 (ignore complexity) if config.arbitrary_types_allowed: yield make_arbitrary_type_validator(type_) else: - raise RuntimeError( - f'no validator found for {type_} see `keep_untouched` or `arbitrary_types_allowed` in Config' - ) + raise RuntimeError(f'no validator found for {type_}, see `arbitrary_types_allowed` in Config') def _find_supertype(type_: AnyType) -> Optional[AnyType]: diff --git a/tests/test_main.py b/tests/test_main.py index 8848c7b..29c7f94 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -953,7 +953,7 @@ def test_custom_types_fail_without_keep_untouched(): assert str(e.value) == ( "no validator found for ." - "_ClassPropertyDescriptor'> see `keep_untouched` or `arbitrary_types_allowed` in Config" + "_ClassPropertyDescriptor'>, see `arbitrary_types_allowed` in Config" ) class Model(BaseModel):