The Fix
pip install pydantic==2.6.4
Based on closed pydantic/pydantic issue #8896 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -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)
pydantic version: 2.6.1
pydantic-core version: 2.16.2
pydantic-core build: profile=release pgo=true
install path: /home/user/.local/lib/python3.12/site-packages/pydantic
python version: 3.12.1 (main, Dec 18 2023, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)]
platform: Linux-6.7.5-200.fc39.x86_64-x86_64-with-glibc2.38
related packages: fastapi-0.109.2 pydantic-settings-2.2.1 typing_extensions-4.8.0
commit: unknown
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\npip install pydantic==2.6.4\nWhen NOT to use: This fix is not applicable if the method is called correctly on subclasses of BaseModel.\n\n
Why This Fix Works in Production
- Trigger: AssertionError: this is a bug! please report it
- Mechanism: Calling model_json_schema() on BaseModel instead of its subclasses leads to an assertion error
- Why the fix works: Adds a more helpful error message when `model_json_schema()` is called on `BaseModel`, addressing issue #8896. (first fixed release: 2.6.4).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Shows up under Python 3.12 in real deployments (not just unit tests).
- Calling model_json_schema() on BaseModel instead of its subclasses leads to an assertion error
- Surfaces as: Traceback (most recent call last):
Proof / Evidence
- GitHub issue: #8896
- Fix PR: https://github.com/pydantic/pydantic/pull/8928
- First fixed release: 2.6.4
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.43
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@sydney-runkle Yes, it is completely clear that calling model_json_schema() does not make a lot of sense”
“@hsteinhaus, Thanks for reporting this. schema_json(), or the new (not deprecated) version of said function model_json_schema() are meant to be called on subclasses of BaseModel,…”
“Reopening, we can add a more descriptive error for the case when it's being called on BaseModel.”
Failure Signature (Search String)
- AssertionError: this is a bug! please report it
Error Message
Stack trace
Error Message
-------------
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/holger-local/.local/lib/python3.12/site-packages/pydantic/main.py", line 1287, in schema_json
cls.model_json_schema(by_alias=by_alias, ref_template=ref_template),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/holger-local/.local/lib/python3.12/site-packages/pydantic/main.py", line 391, in model_json_schema
return model_json_schema(
^^^^^^^^^^^^^^^^^^
File "/home/holger-local/.local/lib/python3.12/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
pydantic version: 2.6.1
pydantic-core version: 2.16.2
pydantic-core build: profile=release pgo=true
install path: /home/user/.local/lib/python3.12/site-packages/pydantic
python version: 3.12.1 (main, Dec 18 2023, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)]
platform: Linux-6.7.5-200.fc39.x86_64-x86_64-with-glibc2.38
related packages: fastapi-0.109.2 pydantic-settings-2.2.1 typing_extensions-4.8.0
commit: unknown
Environment
- Python: 3.12
- Pydantic: 2
What Broke
Users encounter an assertion error when calling schema_json() on BaseModel, causing confusion.
Why It Broke
Calling model_json_schema() on BaseModel instead of its subclasses leads to an assertion error
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.6.4
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.
When NOT to Use This Fix
- This fix is not applicable if the method is called correctly on subclasses of BaseModel.
Verify Fix
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
| Version | Status |
|---|---|
| 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.