Jump to solution
Verify

The Fix

pip install pydantic==2.6.4

Based on closed pydantic/pydantic issue #9261 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -2176,9 +2176,14 @@ def model_json_schema( The generated JSON Schema. """ + from .main import BaseModel + schema_generator_instance = schema_generator(by_alias=by_alias, ref_template=ref_template)
repro.py
% 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
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install pydantic==2.6.4\nWhen NOT to use: This fix is not applicable if the BaseModel is used correctly.\n\n

Why This Fix Works in Production

  • Trigger: AssertionError: this is a bug! please report it
  • Mechanism: Improves error handling for incorrect usage of `model_json_schema` in Pydantic's BaseModel, addressing an AssertionError issue.
  • Why the fix works: Improves error handling for incorrect usage of `model_json_schema` in Pydantic's BaseModel, addressing an AssertionError issue. (first fixed release: 2.6.4).

Why This Breaks in Prod

  • Shows up under Python 3.11.6 in real deployments (not just unit tests).
  • Surfaces as: >> from pydantic import BaseModel

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“This was raised here: https://github.com/pydantic/pydantic/issues/8896 And improved here: https://github.com/pydantic/pydantic/pull/8928 (available in 2.7).”
@Viicos · 2024-04-16 · source

Failure Signature (Search String)

  • AssertionError: this is a bug! please report it

Error Message

Stack trace
error.txt
Error Message ------------- >> 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

Minimal Reproduction

repro.py
% 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

Environment

  • Python: 3.11.6
  • Pydantic: 2

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==2.6.4

When NOT to use: This fix is not applicable if the BaseModel is used correctly.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/pydantic/pydantic/pull/8928

First fixed release: 2.6.4

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if the BaseModel is used correctly.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.

Version Compatibility Table

VersionStatus
2.6.4 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.