Jump to solution
Verify

The Fix

pip install pydantic==2.7.1

Based on closed pydantic/pydantic issue #9216 · 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,7 +2,9 @@ import dataclasses -from typing import Callable, Literal +from typing import Any, Callable, Literal +
repro.py
from pydantic import BaseModel, Field, AliasChoices class FooBase(BaseModel): foo: str = Field(serialization_alias='bar', validation_alias=AliasChoices('bar', 'foo')) FooBase.model_construct().dict()
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.7.1\nWhen NOT to use: Do not use this fix if the model does not utilize validation_alias with AliasChoices.\n\n

Why This Fix Works in Production

  • Trigger: FooBase.model_construct().dict()
  • Mechanism: The TypeError occurs due to an unhashable type 'AliasChoices' in the model_construct method
  • Why the fix works: Fixes the TypeError in model_construct when using validation_alias with AliasChoices. (first fixed release: 2.7.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.11 in real deployments (not just unit tests).
  • The TypeError occurs due to an unhashable type 'AliasChoices' in the model_construct method
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

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
affected (exit=None)
fixed (exit=0)

Discussion

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

“@twispt, Thanks for reporting this! We'll work on a fix and get a patch release out early next week!”
@sydney-runkle · 2024-04-12 · source
“I believe this was introduced with https://github.com/pydantic/pydantic/pull/9144”
@sydney-runkle · 2024-04-12 · source
“Working on a fix now and will have a PR up shortly!”
@sydney-runkle · 2024-04-12 · source
“I am running into the same issue, and can confirm the code works on v2.6.4 but not on v2.7.0 in v2.6.4 i do not see…”
@kevanpigott · 2024-04-11 · source

Failure Signature (Search String)

  • FooBase.model_construct().dict()

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "/home/bryan/src/temp/pydantic-regression/my.py", line 6, in <module> FooBase.model_construct().dict() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/twispt/src/temp/pydantic-regression/.venv/lib/python3.11/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: 'AliasChoices'

Minimal Reproduction

repro.py
from pydantic import BaseModel, Field, AliasChoices class FooBase(BaseModel): foo: str = Field(serialization_alias='bar', validation_alias=AliasChoices('bar', 'foo')) FooBase.model_construct().dict()

Environment

  • Python: 3.11
  • Pydantic: 2

What Broke

Using model_construct results in a TypeError, preventing model instantiation.

Why It Broke

The TypeError occurs due to an unhashable type 'AliasChoices' in the model_construct method

Fix Options (Details)

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

pip install pydantic==2.7.1

When NOT to use: Do not use this fix if the model does not utilize validation_alias with AliasChoices.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if the model does not utilize validation_alias with AliasChoices.

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