Jump to solution
Verify

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

Jump to Verify Open PR/Commit
@@ -644,6 +644,7 @@ def _apply_discriminator_to_union( schema, discriminator, + self.defs._definitions, ) except _discriminated_union.MissingDefinitionForUnionRef:
repro.py
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
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.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).
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.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

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.”
@Viicos · 2025-04-01 · confirmation · source

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

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

When NOT to use: This fix should not be used if the model is intended to work with union types.

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

When NOT to use: Do not use if you need features or security fixes in newer releases.

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.

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 is intended to work with union types.
  • Do not use if you need features or security fixes in newer releases.

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