The Fix
pip install pydantic==1.10.1
Based on closed pydantic/pydantic issue #10682 · PR/commit linked
@@ -107,6 +107,7 @@ clean:
.PHONY: docs
docs:
+ flake8 --max-line-length=80 docs/examples/
python docs/build/main.py
mkdocs build
from pydantic import BaseModel, TypeAdapter, model_serializer
from pydantic_core.core_schema import SerializerFunctionWrapHandler
class CodedValue(BaseModel):
def model_post_init(self, context: object, /):
self._a = None
class Data(CodedValue): ...
class Base(BaseModel):
a: Data = Data()
@model_serializer(mode="wrap")
def _(self, fn: SerializerFunctionWrapHandler) -> dict[str, object]:
return fn(self)
class A(Base): ...
class B(Base): ...
v = A()
TypeAdapter(A | B).dump_python(v, 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: Do not apply this fix if the serialization behavior is intended to remain unchanged.\n\n
Why This Fix Works in Production
- Trigger: pydantic_core._pydantic_core.PydanticSerializationError: Pydantic serializer warnings:
- Mechanism: Invalid serialization warning occurs due to unexpected value types in union serialization
- Why the fix works: Adds linting for documentation and examples to improve code quality and maintainability. (first fixed release: 1.10.1).
Why This Breaks in Prod
- Invalid serialization warning occurs due to unexpected value types in union serialization
- Surfaces as: pydantic_core._pydantic_core.PydanticSerializationError: Pydantic serializer warnings:
Proof / Evidence
- GitHub issue: #10682
- Fix PR: https://github.com/pydantic/pydantic-core/pull/1530
- 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.53
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Yeah, warnings here could be improved. We've tried to improve serialization warnings for unions, but there are a few edge cases that are still a…”
“its not that the warning could be improved, it's completely invalid, this rather large and convoluted example is completely minified as far as I can…”
“> Yeah, warnings here could be improved. I suppose I mean, serialization warnings for unions could be improved across the board.”
Failure Signature (Search String)
- pydantic_core._pydantic_core.PydanticSerializationError: Pydantic serializer warnings:
Error Message
Stack trace
Error Message
-------------
pydantic_core._pydantic_core.PydanticSerializationError: Pydantic serializer warnings:
PydanticSerializationUnexpectedValue: Unexpected Value
PydanticSerializationUnexpectedValue: Expected `B` but got `A` with value `A(a=Data())` - serialized value may not be as expected
Minimal Reproduction
from pydantic import BaseModel, TypeAdapter, model_serializer
from pydantic_core.core_schema import SerializerFunctionWrapHandler
class CodedValue(BaseModel):
def model_post_init(self, context: object, /):
self._a = None
class Data(CodedValue): ...
class Base(BaseModel):
a: Data = Data()
@model_serializer(mode="wrap")
def _(self, fn: SerializerFunctionWrapHandler) -> dict[str, object]:
return fn(self)
class A(Base): ...
class B(Base): ...
v = A()
TypeAdapter(A | B).dump_python(v, warnings="error")
Environment
- Pydantic: 2
What Broke
Users experience incorrect serialization warnings leading to confusion and potential data handling issues.
Why It Broke
Invalid serialization warning occurs due to unexpected value types in union serialization
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/1530
First fixed release: 1.10.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not apply this fix if the serialization behavior is intended to remain unchanged.
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.