The Fix
pip install pydantic==1.10.1
Based on closed pydantic/pydantic issue #9101 · 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%.
@@ -0,0 +1 @@
@@ -0,0 +1 @@
+add `Config.smart_union` to prevent coercion in `Union` if possible. See [the doc](https://pydantic-docs.helpmanual.io/usage/model_config/#smart-union) for more information
diff --git a/docs/examples/model_config_smart_union_off.py b/docs/examples/model_config_smart_union_off.py
new file mode 100644
from typing import Union
from pydantic import BaseModel, Field
class Point(BaseModel):
x: int
y: int
class Points(BaseModel):
# This works
# points: Union[Point, "Points"] = Field(
# union_mode="smart",
# )
# This ignores the data
points: Union[Point, "Points"] = Field(
union_mode="smart",
default_factory=lambda: Point(x=0, y=0),
)
points = Points(
points={
"x": "1",
"y": "1",
},
)
print(points) # points=Points(points=Point(x=0, y=0))
points = Points(
points={
"x": 1,
"y": 1,
},
)
print(points) # points=Point(x=1, y=1)
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==1.10.1\nWhen NOT to use: Avoid using this fix if the model requires strict coercion for all union types.\n\n
Why This Fix Works in Production
- Trigger: TypeError: The following constraints cannot be applied to list[typing.Union[__main__.Point, __main__.Points]]: 'union_mode'
- Mechanism: The default factory in self-referencing unions prevents proper coercion of input data
- Why the fix works: The `smart_union` option was added to prevent coercion in `Union` if possible, resolving issues with self-referencing unions and default factories. (first fixed release: 1.10.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.11 in real deployments (not just unit tests).
- The default factory in self-referencing unions prevents proper coercion of input data
- Surfaces as: TypeError: The following constraints cannot be applied to list[typing.Union[__main__.Point, __main__.Points]]: 'union_mode'
Proof / Evidence
- GitHub issue: #9101
- Fix PR: https://github.com/pydantic/pydantic/pull/2092
- First fixed release: 1.10.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.53
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: 1.10.1
- Mode: fixed_only
- Outcome: ok
Logs
points=Point(x=1, y=1)
points=Point(x=1, y=1)
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“> Given that, I think this issue is resolved..”
“> However, if you have a list of Unions, you can't use this trick You can use Annotated on the Union within the List in…”
“To fix, one option is to specify union_mode=left_to_right (see Pydantic docs on Unions).”
“@guillaumegenthial, Ah yes you're right. I didn't understand the issue in its entirety! Thanks for following up.”
Failure Signature (Search String)
- TypeError: The following constraints cannot be applied to list[typing.Union[__main__.Point, __main__.Points]]: 'union_mode'
Error Message
Stack trace
Error Message
-------------
TypeError: The following constraints cannot be applied to list[typing.Union[__main__.Point, __main__.Points]]: 'union_mode'
Minimal Reproduction
from typing import Union
from pydantic import BaseModel, Field
class Point(BaseModel):
x: int
y: int
class Points(BaseModel):
# This works
# points: Union[Point, "Points"] = Field(
# union_mode="smart",
# )
# This ignores the data
points: Union[Point, "Points"] = Field(
union_mode="smart",
default_factory=lambda: Point(x=0, y=0),
)
points = Points(
points={
"x": "1",
"y": "1",
},
)
print(points) # points=Points(points=Point(x=0, y=0))
points = Points(
points={
"x": 1,
"y": 1,
},
)
print(points) # points=Point(x=1, y=1)
Environment
- Python: 3.11
- Pydantic: 2
What Broke
Data that could be coerced is ignored, leading to unexpected model behavior.
Why It Broke
The default factory in self-referencing unions prevents proper coercion of input data
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.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/2092
First fixed release: 1.10.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Avoid using this fix if the model requires strict coercion for all union types.
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 |
|---|---|
| 1.10.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.