Jump to solution
Verify

The Fix

pip install pydantic==1.10.15

Based on closed pydantic/pydantic issue #9118 · 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
@@ -433,9 +433,9 @@ class CollectedInvalid(Exception): schema = self.collect_definitions(schema) schema = simplify_schema_references(schema) - schema = _discriminated_union.apply_discriminators(schema) if collect_invalid_schemas(schema): raise self.CollectedInvalid()
repro.py
from __future__ import annotations from typing import Annotated, Literal, List, Union from pydantic import BaseModel, Field class Dog(BaseModel): type_: Literal['dog'] friends: List[Pet] class Cat(BaseModel): type_: Literal['cat'] friends: List[Pet] Pet = Annotated[Union[Dog, Cat], Field(..., discriminator='type_')]
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==1.10.15\nWhen NOT to use: This fix should not be applied if the model structure is fundamentally altered.\n\nOption B — Safe version pin\npip install pydantic==2.6.3\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: BooCondition = create_conditions_type(Foo)
  • Mechanism: The error occurs due to a bug in handling unsubstituted type variables in discriminated unions
  • Why the fix works: Fixes a bug related to discriminated unions in Pydantic that caused a TypeError when using unsubstituted type variables. (first fixed release: 1.10.15).
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

  • Triggered by an upgrade/regression window: 2.6.4 breaks; 1.10.15 is the first fixed release.
  • The error occurs due to a bug in handling unsubstituted type variables in discriminated unions
  • Surfaces as: File "C:\Users\tom.mclean\AppData\Roaming\JetBrains\PyCharmCE2023.3\scratches\scratch_6.py", line 102, in <module>

Proof / Evidence

  • GitHub issue: #9118
  • Fix PR: https://github.com/pydantic/pydantic/pull/9124
  • First fixed release: 1.10.15
  • Affected versions: 2.6.4
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-09
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.40

Discussion

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

“I've opened a PR with a fix - this will be released in 2.7 soon (beginning of next week)”
@sydney-runkle · 2024-03-27 · confirmation · source
“> I've opened a PR with a fix - this will be released in 2.7 soon (beginning of next week) Amazing! Thanks!”
@mcleantom · 2024-03-27 · confirmation · source
“@mcleantom, Thanks a ton for reporting this. We'll look into a fix for 2.7!”
@sydney-runkle · 2024-03-27 · source
“So I'll note that without the generic complexity, this simplified version works: I'm working on creating an MRE with the generic complexity.”
@sydney-runkle · 2024-03-27 · source

Failure Signature (Search String)

  • BooCondition = create_conditions_type(Foo)

Error Message

Stack trace
error.txt
Error Message ------------- File "C:\Users\tom.mclean\AppData\Roaming\JetBrains\PyCharmCE2023.3\scratches\scratch_6.py", line 102, in <module> BooCondition = create_conditions_type(Foo) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tom.mclean\AppData\Roaming\JetBrains\PyCharmCE2023.3\scratches\scratch_6.py", line 87, in create_conditions_type AndCondition[return_value_type], ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File "C:\Users\tom.mclean\AppData\Local\miniconda3\envs\Module\Lib\site-packages\pydantic\main.py", line 687, in __class_getitem__ submodel = _generics.create_generic_submodel(model_name, origin, args, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tom.mclean\AppData\Local\miniconda3\envs\Module\Lib\site-packages\pydantic\_internal\_generics.py", line 138, in create_generic_submodel created_model = meta( ^^^^^ File "C:\Users\tom.mclean\AppData\Local\miniconda3\envs\Module\Lib\site-packages\pydantic\_internal\_model_construction.py", line 178, in __new__ set_model_fields(cls, bases, config_wrapper, types_namespace) File "C:\Users\tom.mclean\AppData\Local\miniconda3\envs\Module\Lib\site-packages\pydantic\_internal\_model_construction.py", line 452, in set_model_fields fields, class_vars = collect_model_fields(cls, bases, config_wrapper, types_namespace, typevars_map=typevars ... (truncated) ...

Minimal Reproduction

repro.py
from __future__ import annotations from typing import Annotated, Literal, List, Union from pydantic import BaseModel, Field class Dog(BaseModel): type_: Literal['dog'] friends: List[Pet] class Cat(BaseModel): type_: Literal['cat'] friends: List[Pet] Pet = Annotated[Union[Dog, Cat], Field(..., discriminator='type_')]

Environment

  • Pydantic: 2

What Broke

Users experience TypeErrors when using complex Pydantic models with discriminated unions.

Why It Broke

The error occurs due to a bug in handling unsubstituted type variables in discriminated unions

Fix Options (Details)

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

pip install pydantic==1.10.15

When NOT to use: This fix should not be applied if the model structure is fundamentally altered.

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

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/9124

First fixed release: 1.10.15

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 applied if the model structure is fundamentally altered.
  • 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.6.3 Working
2.6.4 Broken
1.10.15 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.