The Fix
pip install pydantic==2.11.5
Based on closed pydantic/pydantic issue #11934 · 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%.
@@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
??? api "API Documentation"
- [`pydantic.dataclasses.dataclass`][pydantic.dataclasses.dataclass]<br>
+ [`@pydantic.dataclasses.dataclass`][pydantic.dataclasses.dataclass]<br>
from dataclasses import dataclass
import pydantic
def test_method_override_in_subclass():
@dataclass
class MyPythonBase:
n: int = 0
def __repr__(self):
return f"MyPythonBase<n: {self.n}>"
@pydantic.dataclasses.dataclass
class MyPydanticBase:
n: int = 0
def __repr__(self):
return f"MyPydanticBase<n: {self.n}>"
@dataclass
class MyPythonSubclass(MyPythonBase):
def __repr__(self):
return f"MyPythonSubclass<n: {self.n}>"
@pydantic.dataclasses.dataclass
class MyPydanticSubclassFromPython(MyPythonBase):
def __repr__(self):
return f"MyPydanticSubclassFromPython<n: {self.n}>"
@pydantic.dataclasses.dataclass
class MyPydanticSubclassFromPydantic(MyPydanticBase):
def __repr__(self):
return f"MyPydanticSubclassFromPydantic<n: {self.n}>"
print(repr(MyPythonBase(n=1)))
print(repr(MyPythonSubclass(n=2)))
print(repr(MyPydanticBase(n=3)))
print(repr(MyPydanticSubclassFromPython(n=4)))
print(repr(MyPydanticSubclassFromPydantic(n=5)))
if __name__ == "__main__":
test_method_override_in_subclass()
# Output:
# MyPythonBase<n: 1>
# MyPythonSubclass<n: 2>
# MyPydanticBase<n: 3>
# test_method_override_in_subclass.<locals>.MyPydanticSubclassFromPython(n=4)
# MyPydanticSubclassFromPydantic<n: 5>
# Expected Output:
# MyPythonBase<n: 1>
# MyPythonSubclass<n: 2>
# MyPydanticBase<n: 3>
# MyPydanticSubclassFromPython<n: 4>
# MyPydanticSubclassFromPydantic<n: 5>
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.11.5\nWhen NOT to use: This fix should not be used if the application relies on the original behavior of the magic methods.\n\n
Why This Fix Works in Production
- Trigger: Cannot override certain magic methods in Pydantic dataclass subclasses of native dataclasses
- Mechanism: Overriding certain magic methods in Pydantic dataclass subclasses of native dataclasses did not work as expected
- Why the fix works: Fixes the issue where overriding certain magic methods in Pydantic dataclass subclasses of native dataclasses did not work as expected. (first fixed release: 2.11.5).
- 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
- Overriding certain magic methods in Pydantic dataclass subclasses of native dataclasses did not work as expected
- Production symptom (often without a traceback): Cannot override certain magic methods in Pydantic dataclass subclasses of native dataclasses
Proof / Evidence
- GitHub issue: #11934
- Fix PR: https://github.com/pydantic/pydantic/pull/11822
- First fixed release: 2.11.5
- 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.41
Verified Execution
We executed the runnable minimal repro in a temporary environment and captured exit codes + logs.
- Status: PASS
- Ran: 2026-02-11T16:52:29Z
- Package: pydantic
- Fixed: 2.11.5
- Mode: fixed_only
- Outcome: ok
Logs
MyPythonBase<n: 1>
MyPythonSubclass<n: 2>
MyPydanticBase<n: 3>
test_method_override_in_subclass.<locals>.MyPydanticSubclassFromPython(n=4)
MyPydanticSubclassFromPydantic<n: 5>
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“This happened to be fixed by https://github.com/pydantic/pydantic/pull/11822, which will be included in the v2.12 release.”
Failure Signature (Search String)
- Cannot override certain magic methods in Pydantic dataclass subclasses of native dataclasses
Copy-friendly signature
Failure Signature
-----------------
Cannot override certain magic methods in Pydantic dataclass subclasses of native dataclasses
python version: 3.12.4 (main, Jun 6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)]
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Cannot override certain magic methods in Pydantic dataclass subclasses of native dataclasses
python version: 3.12.4 (main, Jun 6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)]
Minimal Reproduction
from dataclasses import dataclass
import pydantic
def test_method_override_in_subclass():
@dataclass
class MyPythonBase:
n: int = 0
def __repr__(self):
return f"MyPythonBase<n: {self.n}>"
@pydantic.dataclasses.dataclass
class MyPydanticBase:
n: int = 0
def __repr__(self):
return f"MyPydanticBase<n: {self.n}>"
@dataclass
class MyPythonSubclass(MyPythonBase):
def __repr__(self):
return f"MyPythonSubclass<n: {self.n}>"
@pydantic.dataclasses.dataclass
class MyPydanticSubclassFromPython(MyPythonBase):
def __repr__(self):
return f"MyPydanticSubclassFromPython<n: {self.n}>"
@pydantic.dataclasses.dataclass
class MyPydanticSubclassFromPydantic(MyPydanticBase):
def __repr__(self):
return f"MyPydanticSubclassFromPydantic<n: {self.n}>"
print(repr(MyPythonBase(n=1)))
print(repr(MyPythonSubclass(n=2)))
print(repr(MyPydanticBase(n=3)))
print(repr(MyPydanticSubclassFromPython(n=4)))
print(repr(MyPydanticSubclassFromPydantic(n=5)))
if __name__ == "__main__":
test_method_override_in_subclass()
# Output:
# MyPythonBase<n: 1>
# MyPythonSubclass<n: 2>
# MyPydanticBase<n: 3>
# test_method_override_in_subclass.<locals>.MyPydanticSubclassFromPython(n=4)
# MyPydanticSubclassFromPydantic<n: 5>
# Expected Output:
# MyPythonBase<n: 1>
# MyPythonSubclass<n: 2>
# MyPydanticBase<n: 3>
# MyPydanticSubclassFromPython<n: 4>
# MyPydanticSubclassFromPydantic<n: 5>
Environment
- Pydantic: 2
What Broke
The overridden methods were not executed, leading to unexpected behavior in the application.
Why It Broke
Overriding certain magic methods in Pydantic dataclass subclasses of native dataclasses did not work as expected
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.11.5
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/11822
First fixed release: 2.11.5
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the application relies on the original behavior of the magic methods.
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.11.5 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.