Jump to solution
Verify

The Fix

pip install pydantic==2.12.1

Based on closed pydantic/pydantic issue #12353 · 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
@@ -2,6 +2,7 @@ from __future__ import annotations as _annotations +import sys import types from collections import deque
repro.py
from pydantic import BaseModel, model_validator class Model(BaseModel): @model_validator(mode="before") def check(self) -> Model: return self
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.12.1\nWhen NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.\n\n

Why This Fix Works in Production

  • Trigger: class Model(BaseModel):
  • Mechanism: Methods decorated with `model_validator` incorrectly handle return type annotations when using the containing class's name
  • Why the fix works: Fixes an issue where methods decorated with `model_validator` would run into errors when annotated with the containing class's name as the return type. (first fixed release: 2.12.1).
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.14 in real deployments (not just unit tests).
  • Methods decorated with `model_validator` incorrectly handle return type annotations when using the containing class's name
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

Discussion

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

“This will be fixed in the next patch release. I assumed you meant to use an _after_ validator in your example? If not, note that…”
@Viicos · 2025-10-08 · confirmation · source
“Yup, I ran into the issue with after, but tried it with before to see if there was any difference. Thank you and I agree…”
@bijlpieter · 2025-10-08 · source
“This is not considered as a regression, as Python 3.14 wasn't supported before 2.12 and you are making use of a 3.14 specific feature (deferred…”
@Viicos · 2025-10-08 · source

Failure Signature (Search String)

  • class Model(BaseModel):

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "/home/pieter/foo.py", line 10, in <module> class Model(BaseModel): ...<2 lines>... return self File "/home/pieter/foo.py", line 11, in Model @model_validator(mode="before") ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^ File "/home/pieter/.cache/uv/environments-v2/foo-af0ca88c5d3839c8/lib/python3.14/site-packages/pydantic/functional_validators.py", line 723, in dec f = _decorators.ensure_classmethod_based_on_signature(f) File "/home/pieter/.cache/uv/environments-v2/foo-af0ca88c5d3839c8/lib/python3.14/site-packages/pydantic/_internal/_decorators.py", line 711, in ensure_classmethod_based_on_signature ) and _is_classmethod_from_sig(function): ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ File "/home/pieter/.cache/uv/environments-v2/foo-af0ca88c5d3839c8/lib/python3.14/site-packages/pydantic/_internal/_decorators.py", line 717, in _is_classmethod_from_sig sig = signature(unwrap_wrapped_function(function)) File "/home/pieter/.local/share/uv/python/cpython-3.14.0-linux-x86_64-gnu/lib/python3.14/inspect.py", line 3312, in signature return Signature.from_callable(obj, follow_wrapped=follow_wrapped, ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ globals=globals, locals=locals, eval_str=eval_str, ^^^^^^^^^^^^^^^^^^^ ... (truncated) ...

Minimal Reproduction

repro.py
from pydantic import BaseModel, model_validator class Model(BaseModel): @model_validator(mode="before") def check(self) -> Model: return self

Environment

  • Python: 3.14
  • Pydantic: 2

What Broke

Users encounter errors when using model validators with specific return type annotations.

Why It Broke

Methods decorated with `model_validator` incorrectly handle return type annotations when using the containing class's name

Fix Options (Details)

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

pip install pydantic==2.12.1

When NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.

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

First fixed release: 2.12.1

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 if it changes public behavior or if the failure cannot be reproduced.

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

Related Issues

No related fixes found.

Sources

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