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%.
@@ -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 🦆
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'}
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.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).
- 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
- GitHub issue: #9049
- Fix PR: https://github.com/pydantic/pydantic/pull/8830
- First fixed release: 1.10.15
- 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.60
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:”
“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…”
“https://github.com/pydantic/pydantic-core/pull/1478 will make the runtime flag about as permissive as it can possibly be.”
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
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 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
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
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.
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.
When NOT to Use This Fix
- This fix is not suitable if strict type enforcement is required during serialization.
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.15 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.