Jump to solution
Verify

The Fix

pip install pydantic==2.6.0

Based on closed pydantic/pydantic issue #8647 · 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
Traceback (most recent call last): File "/tmp/pydantic/noworky.py", line 6, in <module> class Foo(BaseModel, extra="allow"): File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 182, in __new__ complete_model_class( File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 491, in complete_model_class schema = cls.__get_pydantic_core_schema__(cls, handler) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/main.py", line 578, in __get_pydantic_core_schema__ return __handler(__source) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__ schema = self._handler(__source_type) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 468, in generate_schema schema = self._generate_schema(obj) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 700, in _generate_schema schema = self._post_process_generated_schema(self._generate_schema_inner(obj)) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 722, in _generate_schema_inner return self._model_schema(obj) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 512, in _model_schema raise PydanticSchemaGenerationError( pydantic.errors.PydanticSchemaGenerationError: The type annotation for `__pydantic_extra__` must be `Dict[str, ...]` For further information visit https://errors.pydantic.dev/2.5/u/schema-for-unknown-type
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: This fix should not be used if the type hint is intentionally set to a non-dict type.\n\n

Why This Fix Works in Production

  • Trigger: class Foo(BaseModel, extra="allow"):
  • Mechanism: The type annotation for `__pydantic_extra__` is incorrectly treated as a string when using future annotations
  • Why the fix works: Handles the `__pydantic_extra__` annotation being a string or inherited, fixing the schema generation error when using future 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__` is incorrectly treated as a string when using future annotations
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

Discussion

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

“@alexmojaki, Could you please take a look at this issue when you have a chance? Thanks!”
@sydney-runkle · 2024-01-28 · source

Failure Signature (Search String)

  • class Foo(BaseModel, extra="allow"):

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "/tmp/pydantic/noworky.py", line 6, in <module> class Foo(BaseModel, extra="allow"): File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 182, in __new__ complete_model_class( File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 491, in complete_model_class schema = cls.__get_pydantic_core_schema__(cls, handler) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/main.py", line 578, in __get_pydantic_core_schema__ return __handler(__source) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__ schema = self._handler(__source_type) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 468, in generate_schema schema = self._generate_schema(obj) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 700, in _generate_schema schema = self._post_process_generated_schema(self._generate_schema_inner(obj)) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 722, in _generate_schema_inner return self._model_schema(obj) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_i ... (truncated) ...

Minimal Reproduction

repro.py
Traceback (most recent call last): File "/tmp/pydantic/noworky.py", line 6, in <module> class Foo(BaseModel, extra="allow"): File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 182, in __new__ complete_model_class( File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 491, in complete_model_class schema = cls.__get_pydantic_core_schema__(cls, handler) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/main.py", line 578, in __get_pydantic_core_schema__ return __handler(__source) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__ schema = self._handler(__source_type) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 468, in generate_schema schema = self._generate_schema(obj) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 700, in _generate_schema schema = self._post_process_generated_schema(self._generate_schema_inner(obj)) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 722, in _generate_schema_inner return self._model_schema(obj) File "/tmp/pydantic/venv/lib/python3.10/site-packages/pydantic/_internal/_generate_schema.py", line 512, in _model_schema raise PydanticSchemaGenerationError( pydantic.errors.PydanticSchemaGenerationError: The type annotation for `__pydantic_extra__` must be `Dict[str, ...]` For further information visit https://errors.pydantic.dev/2.5/u/schema-for-unknown-type

Environment

  • Python: 3.10
  • Pydantic: 2

What Broke

Users encounter schema generation errors when using `from __future__ import annotations`.

Why It Broke

The type annotation for `__pydantic_extra__` is incorrectly treated as a string when using future annotations

Fix Options (Details)

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

pip install pydantic==2.6.0

When NOT to use: This fix should not be used if the type hint is intentionally set to a non-dict type.

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

  • This fix should not be used if the type hint is intentionally set to a non-dict type.

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.