Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify documentation and error message about keep_untouched #926

Merged
merged 5 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/926-retnikt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarify usage of `remove_untouched`, improve error message for types with no validators.
4 changes: 2 additions & 2 deletions docs/usage/model_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions pydantic/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ def class_name(cls) -> str:

assert str(e.value) == (
"no validator found for <class 'tests.test_main.test_custom_types_fail_without_keep_untouched.<locals>."
"_ClassPropertyDescriptor'> see `keep_untouched` or `arbitrary_types_allowed` in Config"
"_ClassPropertyDescriptor'>, see `arbitrary_types_allowed` in Config"
)

class Model(BaseModel):
Expand Down