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

BaseModel.schema_json() throws AssertionError #9261

Closed
1 task done
straz opened this issue Apr 16, 2024 · 2 comments
Closed
1 task done

BaseModel.schema_json() throws AssertionError #9261

straz opened this issue Apr 16, 2024 · 2 comments
Labels
bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation

Comments

@straz
Copy link

straz commented Apr 16, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

In pydantic 2.6.3, python 3.11.6:

Calling BaseModel.schema_json() raises AssertionError: this is a bug! please report it

Example Code

>>> from pydantic import BaseModel
>>> BaseModel.schema_json()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/straz/Library/Python/3.11/lib/python/site-packages/pydantic/main.py", line 1287, in schema_json
    cls.model_json_schema(by_alias=by_alias, ref_template=ref_template),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/straz/Library/Python/3.11/lib/python/site-packages/pydantic/main.py", line 391, in model_json_schema
    return model_json_schema(
           ^^^^^^^^^^^^^^^^^^
  File "/Users/straz/Library/Python/3.11/lib/python/site-packages/pydantic/json_schema.py", line 2176, in model_json_schema
    assert '__pydantic_core_schema__' in cls.__dict__, 'this is a bug! please report it'
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: this is a bug! please report it

Python, Pydantic & OS Version

% python3 -c "import pydantic.version; print(pydantic.version.version_info())"
             pydantic version: 2.6.3
        pydantic-core version: 2.16.3
          pydantic-core build: profile=release pgo=true
                 install path: /Users/straz/Library/Python/3.11/lib/python/site-packages/pydantic
               python version: 3.11.6 (v3.11.6:8b6ee5ba3b, Oct  2 2023, 11:18:21) [Clang 13.0.0 (clang-1300.0.29.30)]
                     platform: macOS-14.4.1-arm64-arm-64bit
             related packages: fastapi-0.110.0 typing_extensions-4.9.0
                       commit: unknown
@straz straz added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Apr 16, 2024
@Viicos
Copy link
Contributor

Viicos commented Apr 16, 2024

This was raised here: #8896

And improved here: #8928 (available in 2.7).

@sydney-runkle
Copy link
Member

Yep, thanks @Viicos!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation
Projects
None yet
Development

No branches or pull requests

3 participants