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%.
@@ -2,6 +2,7 @@
from __future__ import annotations as _annotations
+import sys
import types
from collections import deque
from pydantic import BaseModel, model_validator
class Model(BaseModel):
@model_validator(mode="before")
def check(self) -> Model:
return self
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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).
- 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
- GitHub issue: #12353
- Fix PR: https://github.com/pydantic/pydantic/pull/12355
- First fixed release: 2.12.1
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.43
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…”
“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…”
“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…”
Failure Signature (Search String)
- class Model(BaseModel):
Error Message
Stack trace
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
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
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.
When NOT to Use This Fix
- Do not use if it changes public behavior or if the failure cannot be reproduced.
Verify Fix
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
| Version | Status |
|---|---|
| 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.