Jump to solution
Verify

The Fix

pip install pydantic==1.10.1

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

Jump to Verify Open PR/Commit
@@ -0,0 +1 @@ @@ -0,0 +1 @@ +Update constr regex example to include start and end lines \ No newline at end of file diff --git a/docs/examples/types_constrained.py b/docs/examples/types_constrained.py
repro.py
from pydantic import BaseModel, Field from typing import Union class FloatThenInt(BaseModel): value: Union[float, int, str] = Field(union_mode='smart') class IntThenFloat(BaseModel): value: Union[int, float, str] = Field(union_mode='smart') float_then_int = FloatThenInt(value=100) print(f'float then int: {float_then_int.value} {type(float_then_int.value)}') print(float_then_int.model_dump_json()) int_then_float = IntThenFloat(value=100) print(f'int then float: {int_then_float.value} {type(int_then_float.value)}') print(int_then_float.model_dump_json())
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: This fix should not be used if strict type enforcement is required for all Union types.\n\n

Why This Fix Works in Production

  • Trigger: I'd say this would only be likely to change if we introduce some element of exactness into union serialization logic, which is in the pipeline, but not high…
  • Mechanism: The union_mode='smart' was not correctly implemented in the model_dump_json method
  • Why the fix works: Fixes the issue where union_mode='smart' was not honored when calling model_dump_json(). (first fixed release: 1.10.1).
Production impact:
  • If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).

Why This Breaks in Prod

  • Shows up under Python 3.9 in real deployments (not just unit tests).
  • The union_mode='smart' was not correctly implemented in the model_dump_json method
  • Production symptom (often without a traceback): python version: 3.9.6 (default, Feb 3 2024, 15:58:27) [Clang 15.0.0 (clang-1500.3.9.4)]

Proof / Evidence

Discussion

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

“I believe I've come across the same issue, but using strict types; Seems to just be the StrictFloat type that isn't actually behaving strictly.”
@henrybetts · 2024-05-10 · source
“Hey @mducar @henrybetts, Thanks for reporting this. Definitely something to be improved. Adding to the union issues milestone!”
@sydney-runkle · 2024-05-16 · source
“Did some more digging - this is the way it is because of https://github.com/pydantic/pydantic-core/pull/866”
@sydney-runkle · 2024-08-09 · source
“I'd say this would only be likely to change if we introduce some element of exactness into union serialization logic, which is in the pipeline,…”
@sydney-runkle · 2024-08-09 · source

Failure Signature (Search String)

  • I'd say this would only be likely to change if we introduce some element of exactness into union serialization logic, which is in the pipeline, but not high prio at the moment.
Copy-friendly signature
signature.txt
Failure Signature ----------------- python version: 3.9.6 (default, Feb 3 2024, 15:58:27) [Clang 15.0.0 (clang-1500.3.9.4)] I'd say this would only be likely to change if we introduce some element of exactness into union serialization logic, which is in the pipeline, but not high prio at the moment.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- python version: 3.9.6 (default, Feb 3 2024, 15:58:27) [Clang 15.0.0 (clang-1500.3.9.4)] I'd say this would only be likely to change if we introduce some element of exactness into union serialization logic, which is in the pipeline, but not high prio at the moment.

Minimal Reproduction

repro.py
from pydantic import BaseModel, Field from typing import Union class FloatThenInt(BaseModel): value: Union[float, int, str] = Field(union_mode='smart') class IntThenFloat(BaseModel): value: Union[int, float, str] = Field(union_mode='smart') float_then_int = FloatThenInt(value=100) print(f'float then int: {float_then_int.value} {type(float_then_int.value)}') print(float_then_int.model_dump_json()) int_then_float = IntThenFloat(value=100) print(f'int then float: {int_then_float.value} {type(int_then_float.value)}') print(int_then_float.model_dump_json())

Environment

  • Python: 3.9
  • Pydantic: 2

What Broke

JSON serialization incorrectly promoted integer values to floats, causing data inconsistency.

Why It Broke

The union_mode='smart' was not correctly implemented in the model_dump_json method

Fix Options (Details)

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

pip install pydantic==1.10.1

When NOT to use: This fix should not be used if strict type enforcement is required for all Union types.

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/1400

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

  • This fix should not be used if strict type enforcement is required for all Union types.

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.