Jump to solution
Verify

The Fix

pip install pydantic==2.6.0

Based on closed pydantic/pydantic issue #8752 · 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%.

Jump to Verify Open PR/Commit
@@ -538,16 +538,23 @@ def _model_schema(self, cls: type[BaseModel]) -> core_schema.CoreSchema: extras_schema = None if core_config.get('extra_fields_behavior') == 'allow': - for tp in (cls, *cls.__mro__): - extras_annotation = cls.__annotations__.get('__pydantic_extra__', None) + assert cls.__mro__[0] is cls
repro.py
from __future__ import annotations # <- removing this line solves the problem from pydantic import BaseModel, ConfigDict class Test(BaseModel): model_config = ConfigDict(extra='allow') __pydantic_extra__: dict[str, str]
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.0\nWhen NOT to use: Do not use this fix if your model does not include `__pydantic_extra__`.\n\n

Why This Fix Works in Production

  • Trigger: class Test(BaseModel):
  • Mechanism: The type annotation for `__pydantic_extra__` was incorrectly defined, causing schema generation errors
  • Why the fix works: Handles the `__pydantic_extra__` annotation being a string or inherited, fixing the type annotation error caused by `from __future__ import annotations`. (first fixed release: 2.6.0).
Production impact:
  • 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.10 in real deployments (not just unit tests).
  • The type annotation for `__pydantic_extra__` was incorrectly defined, causing schema generation errors
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

Discussion

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

“@KasperZutterman, This should be fixed on main, thanks to @alexmojaki's work in https://github.com/pydantic/pydantic/pull/8659.”
@sydney-runkle · 2024-02-07 · confirmation · source

Failure Signature (Search String)

  • class Test(BaseModel):

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "/Users/kasperzutterman/repositories/otainsight/transformations/modules/integrations/transformations/pms/tests/hotelkey/test3.py", line 6, in <module> class Test(BaseModel): File "/Users/kasperzutterman/.pyenv/versions/3.10.12/envs/pydantic/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 183, in __new__ complete_model_class( File "/Users/kasperzutterman/.pyenv/versions/3.10.12/envs/pydantic/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 517, in complete_model_class schema = cls.__get_pydantic_core_schema__(cls, handler) File "/Users/kasperzutterman/.pyenv/versions/3.10.12/envs/pydantic/lib/python3.10/site-packages/pydantic/main.py", line 584, in __get_pydantic_core_schema__ return __handler(__source) File "/Users/kasperzutterman/.pyenv/versions/3.10.12/envs/pydantic/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__ schema = self._handler(__source_type) File "/Users/kasperzutterman/.pyenv/versions/3.10.12/envs/pydantic/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 499, in generate_schema schema = self._generate_schema(obj) File "/Users/kasperzutterman/.pyenv/versions/3.10.12/envs/pydantic/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 73 ... (truncated) ...

Minimal Reproduction

repro.py
from __future__ import annotations # <- removing this line solves the problem from pydantic import BaseModel, ConfigDict class Test(BaseModel): model_config = ConfigDict(extra='allow') __pydantic_extra__: dict[str, str]

Environment

  • Python: 3.10
  • Pydantic: 2

What Broke

Models with `__pydantic_extra__` annotation fail to generate schemas, leading to runtime errors.

Why It Broke

The type annotation for `__pydantic_extra__` was incorrectly defined, causing schema generation errors

Fix Options (Details)

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

pip install pydantic==2.6.0

When NOT to use: Do not use this fix if your model does not include `__pydantic_extra__`.

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/8659

First fixed release: 2.6.0

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

  • Do not use this fix if your model does not include `__pydantic_extra__`.

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.0 Fixed

Related Issues

No related fixes found.

Sources

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