Jump to solution
Verify

The Fix

pip install pydantic==2.6.1

Based on closed pydantic/pydantic issue #8688 · 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
@@ -228,7 +228,7 @@ def _handle_ser_schemas(self, ser_schema: core_schema.SerSchema, f: Walk) -> cor new_definitions: list[core_schema.CoreSchema] = [] for definition in schema['definitions']: - if 'schema_ref' and 'ref' in definition: + if 'schema_ref' in definition and 'ref' in definition: # This indicates a purposely indirect reference
repro.py
import json from typing import Literal, Union from pydantic import BaseModel, Field class Step_A(BaseModel): type: Literal["stepA"] count: int class Step_B(BaseModel): type: Literal["stepB"] value: float class MyModel(BaseModel): type: Literal["mixed"] sub_models: list["SubModel"] steps: Union[Step_A, Step_B] = Field( default=None, discriminator="type", ) class SubModel(MyModel): type: Literal["mixed"] blending: float with open("main.json", "w") as out: json.dump(MyModel.model_json_schema(), out, indent=2)
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.6.1\nWhen NOT to use: Do not apply this fix if you are not using Pydantic version 2.6.\n\n

Why This Fix Works in Production

  • Trigger: Discriminator attribute missing from model schema in a forwardref in pydantic 2.6
  • Mechanism: Fixes a regression in core schema generation for indirect definition references, restoring the discriminator attribute in the model schema.
  • Why the fix works: Fixes a regression in core schema generation for indirect definition references, restoring the discriminator attribute in the model schema. (first fixed release: 2.6.1).
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.11 in real deployments (not just unit tests).
  • Production symptom (often without a traceback): Discriminator attribute missing from model schema in a forwardref in pydantic 2.6

Proof / Evidence

Discussion

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

“@vigneshmanick, Thanks for reporting this. We'll look into a fix to include in a patch release soon!”
@sydney-runkle · 2024-01-31 · source
“Yeah, the issue here is that the core schema is different”
@sydney-runkle · 2024-02-01 · source
“Huh, I thought we tried to fix this via: https://github.com/pydantic/pydantic/issues/8271. Looks like indeed it hasn't yet been fixed. @StrawHatDrag0n, any ideas based on your contribution…”
@sydney-runkle · 2024-02-01 · source
“Hi @vigneshmanick I am seeing the discriminator field in the output”
@StrawHatDrag0n · 2024-02-01 · source

Failure Signature (Search String)

  • Discriminator attribute missing from model schema in a forwardref in pydantic 2.6
  • from the sample code below, the `Submodel` schema is missing the `discriminator` tag for the field `steps` , this is not the case when using version 2.5
Copy-friendly signature
signature.txt
Failure Signature ----------------- Discriminator attribute missing from model schema in a forwardref in pydantic 2.6 from the sample code below, the `Submodel` schema is missing the `discriminator` tag for the field `steps` , this is not the case when using version 2.5

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Discriminator attribute missing from model schema in a forwardref in pydantic 2.6 from the sample code below, the `Submodel` schema is missing the `discriminator` tag for the field `steps` , this is not the case when using version 2.5

Minimal Reproduction

repro.py
import json from typing import Literal, Union from pydantic import BaseModel, Field class Step_A(BaseModel): type: Literal["stepA"] count: int class Step_B(BaseModel): type: Literal["stepB"] value: float class MyModel(BaseModel): type: Literal["mixed"] sub_models: list["SubModel"] steps: Union[Step_A, Step_B] = Field( default=None, discriminator="type", ) class SubModel(MyModel): type: Literal["mixed"] blending: float with open("main.json", "w") as out: json.dump(MyModel.model_json_schema(), out, indent=2)

Environment

  • Python: 3.11
  • Pydantic: 2.6

What Broke

The model schema generated for 'steps' lacks the necessary discriminator, causing validation issues.

Fix Options (Details)

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

pip install pydantic==2.6.1

When NOT to use: Do not apply this fix if you are not using Pydantic version 2.6.

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

First fixed release: 2.6.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

  • Do not apply this fix if you are not using Pydantic version 2.6.

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

Related Issues

No related fixes found.

Sources

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