Skip to content

Commit

Permalink
More helpful error re wrong model_json_schema usage (#8928)
Browse files Browse the repository at this point in the history
Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
  • Loading branch information
sydney-runkle and dmontagu committed Mar 1, 2024
1 parent db0f809 commit e1a5c18
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pydantic/json_schema.py
Expand Up @@ -2176,9 +2176,14 @@ def model_json_schema(
Returns:
The generated JSON Schema.
"""
from .main import BaseModel

schema_generator_instance = schema_generator(by_alias=by_alias, ref_template=ref_template)
if isinstance(cls.__pydantic_validator__, _mock_val_ser.MockValSer):
cls.__pydantic_validator__.rebuild()

if cls is BaseModel:
raise AttributeError('model_json_schema() must be called on a subclass of BaseModel, not BaseModel itself.')
assert '__pydantic_core_schema__' in cls.__dict__, 'this is a bug! please report it'
return schema_generator_instance.generate(cls.__pydantic_core_schema__, mode=mode)

Expand Down

0 comments on commit e1a5c18

Please sign in to comment.