Jump to solution
Verify

The Fix

pip install pydantic==2.7.1

Based on closed pydantic/pydantic issue #9220 · PR/commit linked

Production note: This usually shows up under retries/timeouts. Treat it as a side-effect risk until you can verify behavior with a canary + real traffic.

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 AliasChoices, BaseModel, Field class MyModel(BaseModel): data: str our_id: str | None = Field( default=None, validation_alias=AliasChoices("their_id", "theirId", "our_id", "id"), ) def test_cardmodel_eq(): model1 = MyModel.model_construct(data="test data") model2 = MyModel.model_construct(data="test data") model3 = MyModel.model_construct(data="other data") assert model1 == model2 assert not model1 == model3
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: This fix should not be used if the model comparison logic is fundamentally altered.\n\n

Why This Fix Works in Production

  • Trigger: validation_alias=AliasChoices("their_id", "theirId", "our_id", "id"),
  • Mechanism: The validation alias behavior was not correctly implemented for model comparisons, leading to a TypeError
  • Why the fix works: Fixes the validation alias behavior with model construction for AliasChoices and AliasPath, addressing a TypeError encountered during model comparisons. (first fixed release: 2.7.1).
Production impact:
  • If left unfixed, retries/timeouts can trigger duplicate external side-effects (double charges, duplicate emails, repeated writes).

Why This Breaks in Prod

  • Shows up under Python 3.11 in real deployments (not just unit tests).
  • The validation alias behavior was not correctly implemented for model comparisons, leading to a TypeError
  • Production symptom (often without a traceback): validation_alias=AliasChoices("their_id", "theirId", "our_id", "id"),

Proof / Evidence

Discussion

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

“@sydney-runkle I see I have made a typo when writing my example code 🤦🏼~~I will fix it.~~ It should be fixed now”
@iambroadband · 2024-04-12 · confirmation · source
“Closing this as a dupe of https://github.com/pydantic/pydantic/issues/9216, but will make sure to resolve this in the patch release!”
@sydney-runkle · 2024-04-12 · confirmation · source
“@iambroadband, Thanks for reporting this! We'll roll a fix out with a patch release early next week!”
@sydney-runkle · 2024-04-12 · source
“@iambroadband, I don't think your test as it stands should pass - model1 and model2 aren't equivalent, unless I'm missing something?”
@sydney-runkle · 2024-04-12 · source

Failure Signature (Search String)

  • validation_alias=AliasChoices("their_id", "theirId", "our_id", "id"),
  • assert model1 == model2
Copy-friendly signature
signature.txt
Failure Signature ----------------- validation_alias=AliasChoices("their_id", "theirId", "our_id", "id"), assert model1 == model2

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- validation_alias=AliasChoices("their_id", "theirId", "our_id", "id"), assert model1 == model2

Minimal Reproduction

repro.py
from pydantic import AliasChoices, BaseModel, Field class MyModel(BaseModel): data: str our_id: str | None = Field( default=None, validation_alias=AliasChoices("their_id", "theirId", "our_id", "id"), ) def test_cardmodel_eq(): model1 = MyModel.model_construct(data="test data") model2 = MyModel.model_construct(data="test data") model3 = MyModel.model_construct(data="other data") assert model1 == model2 assert not model1 == model3

Environment

  • Python: 3.11
  • Pydantic: 2

What Broke

Model comparisons failed with a TypeError, causing test failures in production.

Why It Broke

The validation alias behavior was not correctly implemented for model comparisons, leading to a TypeError

Fix Options (Details)

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

pip install pydantic==2.7.1

When NOT to use: This fix should not be used if the model comparison logic is fundamentally altered.

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

  • This fix should not be used if the model comparison logic is fundamentally altered.

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.