question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error generate schema for model with custom validators.

See original GitHub issue

Bug

  • 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tiangolocommented, Jan 29, 2019

Done, here’s the PR #375 🙂

1reaction
alexeyproskuryakovcommented, Jan 24, 2019

Thank you! I will wait:)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found