The Fix
pip install pydantic==2.11.2
Based on closed pydantic/pydantic issue #11661 · 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%.
@@ -644,6 +644,7 @@ def _apply_discriminator_to_union(
schema,
discriminator,
+ self.defs._definitions,
)
except _discriminated_union.MissingDefinitionForUnionRef:
from pydantic import BaseModel, Field
from typing import Annotated, Literal
class Foo(BaseModel):
type: Literal["foo"] = "foo"
type FooWithDiscriminator = Annotated[Foo, Field(discriminator="type")]
class Container(BaseModel):
f: FooWithDiscriminator
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.2\nWhen NOT to use: This fix should not be used if the model is intended to work with union types.\n\nOption B — Safe version pin\npip install pydantic==2.11.0\nWhen NOT to use: Do not use if you need features or security fixes in newer releases.\n\n
Why This Fix Works in Production
- Trigger: Model construction fails on non-union types annotated with discriminator.
- Mechanism: The discriminator information was lost when using a PEP-695-style type alias
- Why the fix works: Provides the available definitions when applying discriminated unions, fixing issues in the schema cleaning process related to discriminator metadata. (first fixed release: 2.11.2).
- 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.13 in real deployments (not just unit tests).
- The discriminator information was lost when using a PEP-695-style type alias
- Production symptom (often without a traceback): Model construction fails on non-union types annotated with discriminator.
Proof / Evidence
- GitHub issue: #11661
- Fix PR: https://github.com/pydantic/pydantic/pull/11670
- First fixed release: 2.11.2
- 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.67
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Turns out in 2.11.0 the discriminator info was lost, but no error was thrown. This will be fixed in the next patch release.”
Failure Signature (Search String)
- Model construction fails on non-union types annotated with discriminator.
- Annotating a type with a `discriminator` that is not a union fails with the following error:
Copy-friendly signature
Failure Signature
-----------------
Model construction fails on non-union types annotated with discriminator.
Annotating a type with a `discriminator` that is not a union fails with the following error:
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Model construction fails on non-union types annotated with discriminator.
Annotating a type with a `discriminator` that is not a union fails with the following error:
Minimal Reproduction
from pydantic import BaseModel, Field
from typing import Annotated, Literal
class Foo(BaseModel):
type: Literal["foo"] = "foo"
type FooWithDiscriminator = Annotated[Foo, Field(discriminator="type")]
class Container(BaseModel):
f: FooWithDiscriminator
Environment
- Python: 3.13
- Pydantic: 2
What Broke
Model construction fails with a SchemaError when using a discriminator on non-union types.
Why It Broke
The discriminator information was lost when using a PEP-695-style type alias
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.11.2
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Option B — Safe version pin Backward-compatible pin
pip install pydantic==2.11.0
Use when you can’t upgrade immediately. Plan a follow-up to upgrade (pins can accumulate security/compat debt).
Fix reference: https://github.com/pydantic/pydantic/pull/11670
First fixed release: 2.11.2
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the model is intended to work with union types.
- Do not use if you need features or security fixes in newer releases.
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.0 | Working |
| 2.11.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.