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%.
@@ -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
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)
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.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).
- 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
- GitHub issue: #8688
- Fix PR: https://github.com/pydantic/pydantic/pull/8702
- First fixed release: 2.6.1
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.75
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.46
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!”
“Yeah, the issue here is that the core schema is different”
“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…”
“Hi @vigneshmanick I am seeing the discriminator field in the output”
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
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 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
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
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.
When NOT to Use This Fix
- Do not apply this fix if you are not using Pydantic version 2.6.
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.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.