Jump to solution
Verify

The Fix

pip install pydantic==2.9.2

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

Jump to Verify Open PR/Commit
@@ -448,11 +448,15 @@ def inspect_namespace( # noqa C901 frame = sys._getframe(2) if frame is not None: - ann_type = eval_type_backport( - _make_forward_ref(ann_type, is_argument=False, is_class=True), - globalns=frame.f_globals,
repro.py
from __future__ import annotations from pydantic import BaseModel class ModelB(BaseModel): _foo: ModelA class ModelA(BaseModel): bar: int def main(): model_a=ModelA(bar=1) model_b=ModelB(_foo=model_a) if __name__ == "__main__": main()
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.9.2\nWhen NOT to use: Do not use this fix if your code relies on the previous behavior of private attributes.\n\n

Why This Fix Works in Production

  • Trigger: class ModelB(BaseModel):
  • Mechanism: Fixes an issue where using 'from __future__ import annotations' with private attributes caused a NameError in Pydantic v2.9.0.
  • Why the fix works: Fixes an issue where using 'from __future__ import annotations' with private attributes caused a NameError in Pydantic v2.9.0. (first fixed release: 2.9.2).
Production impact:
  • If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).

Why This Breaks in Prod

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

Discussion

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

“### Initial Checks - [X] I confirm that I'm using Pydantic V2 ### Description Hi all! Thanks for this amazing package, it has really save me SOOO much trouble in recent times. I've just updates from v2.8.2 to v2.9.0 and I've noticed that fr”
Issue thread · issue description · source

Failure Signature (Search String)

  • class ModelB(BaseModel):

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "/home/joao/pydantic_test.py", line 6, in <module> class ModelB(BaseModel): File "/home/joao/.venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 114, in __new__ private_attributes = inspect_namespace( ^^^^^^^^^^^^^^^^^^ File "/home/joao/.venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 448, in inspect_namespace ann_type = eval_type_backport( ^^^^^^^^^^^^^^^^^^^ File "/home/joao/.venv/lib/python3.12/site-packages/pydantic/_internal/_typing_extra.py", line 279, in eval_type_backport return _eval_type_backport(value, globalns, localns, type_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/joao/.venv/lib/python3.12/site-packages/pydantic/_internal/_typing_extra.py", line 303, in _eval_type_backport return _eval_type(value, globalns, localns, type_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/joao/.venv/lib/python3.12/site-packages/pydantic/_internal/_typing_extra.py", line 332, in _eval_type return typing._eval_type( # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/typing.py", line 415, in _eval_type return t._evaluate(globalns, localns, type_params, recursive_guard=recursive_guard) . ... (truncated) ...

Minimal Reproduction

repro.py
from __future__ import annotations from pydantic import BaseModel class ModelB(BaseModel): _foo: ModelA class ModelA(BaseModel): bar: int def main(): model_a=ModelA(bar=1) model_b=ModelB(_foo=model_a) if __name__ == "__main__": main()

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

Code raises NameError when using private attributes in models, causing application crashes.

Fix Options (Details)

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

pip install pydantic==2.9.2

When NOT to use: Do not use this fix if your code relies on the previous behavior of private attributes.

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

First fixed release: 2.9.2

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 code relies on the previous behavior of private attributes.

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

Related Issues

No related fixes found.

Sources

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