The Fix
pip install pydantic==1.10.1
Based on closed pydantic/pydantic issue #10334 · 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%.
@@ -1,6 +1,6 @@
black==19.10b0
coverage==5.1
-Cython==0.29.16;sys_platform!='win32'
+Cython==0.29.17;sys_platform!='win32'
flake8==3.7.9
from typing import Literal
from pydantic import BaseModel, ConfigDict, Field
def to_pascal_case(s: str) -> str:
return "".join(x.capitalize() for x in s.lower().split("_"))
class MyBaseModel(BaseModel):
model_config = ConfigDict(alias_generator=to_pascal_case, populate_by_name=True)
class Cat(MyBaseModel):
pet_type: Literal["cat"] = "cat"
meows: int
class Dog(MyBaseModel):
pet_type: Literal["dog"] = "dog"
barks: float
class Owner(MyBaseModel):
name: str
pet: Cat | Dog = Field(..., discriminator="pet_type")
owner = Owner(name="Alice", pet=Dog(barks=3.14))
owner.model_dump_json(warnings="error")
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==1.10.1\nWhen NOT to use: This fix should not be applied if the alias generator is not used in your models.\n\n
Why This Fix Works in Production
- Trigger: E pydantic_core._pydantic_core.PydanticSerializationError: Pydantic serializer warnings:
- Mechanism: The error occurs due to a bug in tagged union serialization when using an alias generator
- Why the fix works: Fixes a bug related to tagged union serialization when using an alias generator in Pydantic models. (first fixed release: 1.10.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).
- The error occurs due to a bug in tagged union serialization when using an alias generator
- Surfaces as: E pydantic_core._pydantic_core.PydanticSerializationError: Pydantic serializer warnings:
Proof / Evidence
- GitHub issue: #10334
- Fix PR: https://github.com/pydantic/pydantic-core/pull/1442
- First fixed release: 1.10.1
- 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.52
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@brearleyt, Thanks for reporting - definitely a bug with the new tagged union serialization. I'll take a look at this and roll out a fix…”
Failure Signature (Search String)
- E pydantic_core._pydantic_core.PydanticSerializationError: Pydantic serializer warnings:
Error Message
Stack trace
Error Message
-------------
E pydantic_core._pydantic_core.PydanticSerializationError: Pydantic serializer warnings:
E Failed to get discriminator value for tagged union serialization with value `Dog(pet_type='dog', barks=3.14)` - defaulting to left to right union serialization.
Minimal Reproduction
from typing import Literal
from pydantic import BaseModel, ConfigDict, Field
def to_pascal_case(s: str) -> str:
return "".join(x.capitalize() for x in s.lower().split("_"))
class MyBaseModel(BaseModel):
model_config = ConfigDict(alias_generator=to_pascal_case, populate_by_name=True)
class Cat(MyBaseModel):
pet_type: Literal["cat"] = "cat"
meows: int
class Dog(MyBaseModel):
pet_type: Literal["dog"] = "dog"
barks: float
class Owner(MyBaseModel):
name: str
pet: Cat | Dog = Field(..., discriminator="pet_type")
owner = Owner(name="Alice", pet=Dog(barks=3.14))
owner.model_dump_json(warnings="error")
Environment
- Python: 3.11
- Pydantic: 2
What Broke
Users experience serialization errors when using tagged unions with alias generators in Pydantic models.
Why It Broke
The error occurs due to a bug in tagged union serialization when using an alias generator
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.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-core/pull/1442
First fixed release: 1.10.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if the alias generator is not used in your models.
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 |
|---|---|
| 1.10.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.