Jump to solution
Verify

The Fix

pip install pydantic==1.10.1

Based on closed pydantic/pydantic issue #10682 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -107,6 +107,7 @@ clean: .PHONY: docs docs: + flake8 --max-line-length=80 docs/examples/ python docs/build/main.py mkdocs build
repro.py
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")
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.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

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…”
@sydney-runkle · 2024-10-24 · source
“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…”
@KotlinIsland · 2024-10-24 · source
“> Yeah, warnings here could be improved. I suppose I mean, serialization warnings for unions could be improved across the board.”
@sydney-runkle · 2024-10-24 · source

Failure Signature (Search String)

  • pydantic_core._pydantic_core.PydanticSerializationError: Pydantic serializer warnings:

Error Message

Stack trace
error.txt
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

repro.py
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

When NOT to use: Do not apply this fix if the serialization behavior is intended to remain unchanged.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not apply this fix if the serialization behavior is intended to remain unchanged.

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