Error generate schema for model with custom validators.
See original GitHub issueBug
- OS: macOS mojave 10.14 (18A391)
- Python version
import sys; print(sys.version)
: 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:07:29) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] - Pydantic version
import pydantic; print(pydantic.VERSION)
: 0.18.1
This behavior only when have custom fields validators
from pydantic import BaseModel
from typing import Optional
class TestCustomValidatorModelWithOptionalField(BaseModel):
field: Optional[int] = None
@validator('field')
def check_field(cls, v, *, values, config, field):
return v
Output:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/.../lib/python3.6/site-packages/pydantic/main.py", line 292, in schema
s = model_schema(cls, by_alias=by_alias)
File "/Users/.../lib/python3.6/site-packages/pydantic/schema.py", line 193, in model_schema
model, by_alias=by_alias, model_name_map=model_name_map, ref_prefix=ref_prefix
File "/Users/.../lib/python3.6/site-packages/pydantic/schema.py", line 463, in model_process_schema
model, by_alias=by_alias, model_name_map=model_name_map, ref_prefix=ref_prefix
File "/Users/.../lib/python3.6/site-packages/pydantic/schema.py", line 484, in model_type_schema
f, by_alias=by_alias, model_name_map=model_name_map, ref_prefix=ref_prefix
File "/Users/.../lib/python3.6/site-packages/pydantic/schema.py", line 240, in field_schema
ref_prefix=ref_prefix,
File "/Users/.../lib/python3.6/site-packages/pydantic/schema.py", line 442, in field_type_schema
ref_prefix=ref_prefix,
File "/Users/.../lib/python3.6/site-packages/pydantic/schema.py", line 610, in field_singleton_schema
ref_prefix=ref_prefix,
File "/Users/.../lib/python3.6/site-packages/pydantic/schema.py", line 534, in field_singleton_sub_fields_schema
ref_prefix=ref_prefix,
File "/Users/.../lib/python3.6/site-packages/pydantic/schema.py", line 442, in field_type_schema
ref_prefix=ref_prefix,
File "/Users/.../lib/python3.6/site-packages/pydantic/schema.py", line 645, in field_singleton_schema
raise ValueError(f'Value not declarable with JSON Schema, field: {field}')
ValueError: Value not declarable with JSON Schema, field: field_NoneType type=NoneType required
If remove @validator
- all ok.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Error generate schema for model with custom validators. #363
Bug OS: macOS mojave 10.14 (18A391) Python version import sys; print(sys.version): 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, ...
Read more >Mongoose v6.8.0: Validation
Custom Error Messages You can configure the error message for individual validators in your schema. There are two equivalent ways to set the...
Read more >Error in creating a custom validation using mongoose with ...
It's a question of whether the this object passed to the required function has the built-in mongoose.Document properties as well as the ones ......
Read more >Schema Enforcer Custom Validators | The NTC Mag
A custom validator is a Python module that allows you to run any logic against your data on a per-host basis. Let's start...
Read more >How to Use Mongoose Custom Validators - ObjectRocket
In this article, we will discuss how to create mongoose custom validators. Defining schema without validations. We have a details collection and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Done, here’s the PR #375 🙂
Thank you! I will wait:)