Jump to solution
Verify

The Fix

pip install pydantic==1.10.15

Based on closed pydantic/pydantic issue #9049 · 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
@@ -431,9 +431,28 @@ print(m.model_dump()) # note: the password field is not included when adding sensitive information like secrets as fields of subclasses. -### Serializing with duck-typing +### Serializing with duck-typing 🦆
repro.py
from pydantic import BaseModel, ConfigDict, TypeAdapter, SerializeAsAny class Parent(BaseModel): x: int class Other(BaseModel): y: str model_config = ConfigDict(extra='allow') ta = TypeAdapter(Parent) other = Other(x=1, y='hello') print(ta.dump_python(other)) #> {} print(ta.dump_python(other, serialize_as_any=False)) #> {} print(ta.dump_python(other, serialize_as_any=True)) #> {'y': 'hello', 'x': 1} ta = TypeAdapter(SerializeAsAny[Parent]) other = Other(x=1, y='hello') print(ta.dump_python(other)) #> {'y': 'hello', 'x': 1} # note: if extra='ignore', the default was set, we'd get {'y': 'hello'}
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.15\nWhen NOT to use: This fix is not suitable if strict type enforcement is required during serialization.\n\nOption C — Workaround\nthat we considered was having the runtime flag named `duck_type_serialization`, but we ended up deciding not to go with this approach, as it's confusing for users to have "duck type serialization" and "serialize as any" as separate concepts. See [this comment](https://github.com/pydantic/pydantic-core/pull/1194#issuecomment-1997944022) and surrounding comments for more detail.\nWhen NOT to use: This fix is not suitable if strict type enforcement is required during serialization.\n\n

Why This Fix Works in Production

  • Trigger: The following test fails with warnings for passing str where int expected:
  • Mechanism: Behavioral differences exist between `SerializeAsAny` annotation and `serialize_as_any` runtime flag
  • Why the fix works: Supports the `serialize_as_any` runtime setting, addressing behavioral differences in serialization warnings. (first fixed release: 1.10.15).
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

  • Behavioral differences exist between `SerializeAsAny` annotation and `serialize_as_any` runtime flag
  • Production symptom (often without a traceback): The following test fails with warnings for passing str where int expected:

Proof / Evidence

Discussion

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

“Ah, here's another thing to note, though I'm not sure if this merits a change:”
@sydney-runkle · 2024-03-19 · source
“Here's a case with unrelated models where the annotation usage vs runtime flag usage doesn't result in a behavioral discrepancy. This was one we were…”
@sydney-runkle · 2024-03-19 · source
“https://github.com/pydantic/pydantic-core/pull/1478 will make the runtime flag about as permissive as it can possibly be.”
@davidhewitt · 2025-05-21 · source

Failure Signature (Search String)

  • The following test fails with warnings for passing str where int expected:
  • serializer = SchemaSerializer(core_schema.list_schema(core_schema.int_schema()))
Copy-friendly signature
signature.txt
Failure Signature ----------------- The following test fails with warnings for passing str where int expected: serializer = SchemaSerializer(core_schema.list_schema(core_schema.int_schema()))

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- The following test fails with warnings for passing str where int expected: serializer = SchemaSerializer(core_schema.list_schema(core_schema.int_schema()))

Minimal Reproduction

repro.py
from pydantic import BaseModel, ConfigDict, TypeAdapter, SerializeAsAny class Parent(BaseModel): x: int class Other(BaseModel): y: str model_config = ConfigDict(extra='allow') ta = TypeAdapter(Parent) other = Other(x=1, y='hello') print(ta.dump_python(other)) #> {} print(ta.dump_python(other, serialize_as_any=False)) #> {} print(ta.dump_python(other, serialize_as_any=True)) #> {'y': 'hello', 'x': 1} ta = TypeAdapter(SerializeAsAny[Parent]) other = Other(x=1, y='hello') print(ta.dump_python(other)) #> {'y': 'hello', 'x': 1} # note: if extra='ignore', the default was set, we'd get {'y': 'hello'}

What Broke

Serialization warnings are inconsistently raised, leading to unexpected behavior in production.

Why It Broke

Behavioral differences exist between `SerializeAsAny` annotation and `serialize_as_any` runtime flag

Fix Options (Details)

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

pip install pydantic==1.10.15

When NOT to use: This fix is not suitable if strict type enforcement is required during serialization.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Option C — Workaround Temporary workaround

that we considered was having the runtime flag named `duck_type_serialization`, but we ended up deciding not to go with this approach, as it's confusing for users to have "duck type serialization" and "serialize as any" as separate concepts. See [this comment](https://github.com/pydantic/pydantic-core/pull/1194#issuecomment-1997944022) and surrounding comments for more detail.

When NOT to use: This fix is not suitable if strict type enforcement is required during serialization.

Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.

Fix reference: https://github.com/pydantic/pydantic/pull/8830

First fixed release: 1.10.15

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

  • This fix is not suitable if strict type enforcement is required during serialization.

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

Related Issues

No related fixes found.

Sources

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