Jump to solution
Verify

The Fix

pip install pydantic==2.7.0

Based on closed pydantic/pydantic issue #9191 · 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
@@ -536,7 +536,7 @@ def _model_schema(self, cls: type[BaseModel]) -> core_schema.CoreSchema: assert cls.__mro__[-1] is object for candidate_cls in cls.__mro__[:-1]: - extras_annotation = candidate_cls.__annotations__.get('__pydantic_extra__', None) + extras_annotation = getattr(candidate_cls, '__annotations__', {}).get('__pydantic_extra__', None) if extras_annotation is not None:
repro.py
pydantic version: 2.7.0b1 pydantic-core version: 2.18.0 pydantic-core build: profile=release pgo=false python version: 3.9.16 (main, Apr 2 2023, 22:08:02) [Clang 14.0.0 (clang-1400.0.29.202)] platform: macOS-14.2.1-arm64-arm-64bit related packages: mypy-1.9.0 typing_extensions-4.10.0 fastapi-0.109.2 pydantic-settings-2.2.1
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.7.0\nWhen NOT to use: This fix should not be applied if using a version of Pydantic prior to 2.0.\n\n

Why This Fix Works in Production

  • Trigger: AttributeError: type object 'Generic' has no attribute '__annotations__'
  • Mechanism: Fixes an issue where using OpenAI SDK with Pydantic V2.7.0b1 resulted in an AttributeError related to the Generic class.
  • Why the fix works: Fixes an issue where using OpenAI SDK with Pydantic V2.7.0b1 resulted in an AttributeError related to the Generic class. (first fixed release: 2.7.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.9 in real deployments (not just unit tests).
  • Surfaces as: AttributeError: type object 'Generic' has no attribute '__annotations__'

Proof / Evidence

Discussion

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

“Great catch, thank you. We'll look into it.”
@samuelcolvin · 2024-04-08 · source
“Oh nevermind, I was able to reproduce it once I switched to python 3.9”
@dmontagu · 2024-04-09 · source
“We've found the issue and will open a PR with a fix shortly! Should be fixed for 2.7 :).”
@sydney-runkle · 2024-04-09 · source
“@willbakst I think this is a small enough fix that we'll just go ahead with 2.7, but perhaps you could test against main to confirm…”
@sydney-runkle · 2024-04-09 · source

Failure Signature (Search String)

  • AttributeError: type object 'Generic' has no attribute '__annotations__'

Error Message

Stack trace
error.txt
Error Message ------------- AttributeError: type object 'Generic' has no attribute '__annotations__'

Minimal Reproduction

repro.py
pydantic version: 2.7.0b1 pydantic-core version: 2.18.0 pydantic-core build: profile=release pgo=false python version: 3.9.16 (main, Apr 2 2023, 22:08:02) [Clang 14.0.0 (clang-1400.0.29.202)] platform: macOS-14.2.1-arm64-arm-64bit related packages: mypy-1.9.0 typing_extensions-4.10.0 fastapi-0.109.2 pydantic-settings-2.2.1

Environment

  • Python: 3.9
  • Pydantic: 2

Fix Options (Details)

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

pip install pydantic==2.7.0

When NOT to use: This fix should not be applied if using a version of Pydantic prior to 2.0.

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

First fixed release: 2.7.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 applied if using a version of Pydantic prior to 2.0.

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

Related Issues

No related fixes found.

Sources

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