The Fix
pip install pydantic==2.7.1
Based on closed pydantic/pydantic issue #9239 · 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,7 +2,9 @@
import dataclasses
-from typing import Callable, Literal
+from typing import Any, Callable, Literal
+
#!/usr/bin/env python3
from pydantic import AliasPath, BaseModel, Field
class Example(BaseModel):
value: str = Field(validation_alias=AliasPath("data", "value"))
if __name__ == "__main__":
example = Example.model_construct(value="value")
assert example.value == "value"
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.7.1\nWhen NOT to use: Do not use this fix if your code relies on the previous behavior of validation aliases.\n\n
Why This Fix Works in Production
- Trigger: example = Example.model_construct(value="value")
- Mechanism: The error occurs due to unhandled validation aliases for AliasPath in model_construct
- Why the fix works: Fixes the unhashable type error raised from BaseModel.model_construct() by properly handling validation aliases for AliasPath and AliasChoices. (first fixed release: 2.7.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.12 in real deployments (not just unit tests).
- The error occurs due to unhandled validation aliases for AliasPath in model_construct
- Surfaces as: Traceback (most recent call last):
Proof / Evidence
- GitHub issue: #9239
- Fix PR: https://github.com/pydantic/pydantic/pull/9223
- First fixed release: 2.7.1
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.56
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.7.1
- Mode: fixed_only
- Outcome: ok
Logs
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Hi @jessemyers-lettuce, This is fixed on main by https://github.com/pydantic/pydantic/pull/9223. We'll do a patch release with this fix early next week!”
Failure Signature (Search String)
- example = Example.model_construct(value="value")
Error Message
Stack trace
Error Message
-------------
Traceback (most recent call last):
File "/path/to/main.py", line 9, in <module>
example = Example.model_construct(value="value")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/pydantic/main.py", line 228, in model_construct
elif field.validation_alias is not None and field.validation_alias in values:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'AliasPath'
Minimal Reproduction
#!/usr/bin/env python3
from pydantic import AliasPath, BaseModel, Field
class Example(BaseModel):
value: str = Field(validation_alias=AliasPath("data", "value"))
if __name__ == "__main__":
example = Example.model_construct(value="value")
assert example.value == "value"
Environment
- Python: 3.12
- Pydantic: 2
What Broke
Users experience TypeError when constructing models with validation aliases.
Why It Broke
The error occurs due to unhandled validation aliases for AliasPath in model_construct
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.7.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/9223
First fixed release: 2.7.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if your code relies on the previous behavior of validation aliases.
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.7.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.