Jump to solution
Verify

The Fix

pip install pydantic==1.10.1

Based on closed pydantic/pydantic issue #9396 · 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
@@ -0,0 +1 @@ @@ -0,0 +1 @@ +Allow subclasses of known types to be encoded with superclass encoder \ No newline at end of file diff --git a/docs/examples/exporting_models_json.py b/docs/examples/exporting_models_json.py
repro.py
pydantic version: 2.7.1 pydantic-core version: 2.18.2 pydantic-core build: profile=release pgo=true install path: /home/noam/.cache/pypoetry/virtualenvs/hl-7m4wOqun-py3.12/lib/python3.12/site-packages/pydantic python version: 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] platform: Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.39 related packages: typing_extensions-4.10.0 mypy-1.7.1 commit: unknown
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 applied if the application relies on the previous validation behavior.\n\n

Why This Fix Works in Production

  • Trigger: In [1]: import pydantic
  • Mechanism: The validation logic fails to handle the '-' character in negative integer strings
  • Why the fix works: Addresses the issue of parsing negative integer strings in Pydantic by fixing the validation logic. (first fixed release: 1.10.1).
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

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • The validation logic fails to handle the '-' character in negative integer strings
  • Surfaces as: In [1]: import pydantic

Proof / Evidence

Discussion

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

“I investigated this and the issue seems to be in strip_leading_zeros function where if any character occurs except (+, _, 1 ..”
@RajatRajdeep · 2024-05-13 · source
“Hey folks, Thanks for reporting this bug. Definitely something we want to fix in 2.7.2. Should be an easy fix if anyone is interested in…”
@sydney-runkle · 2024-05-14 · source

Failure Signature (Search String)

  • In [1]: import pydantic

Error Message

Stack trace
error.txt
Error Message ------------- In [1]: import pydantic In [2]: class A(pydantic.BaseModel): ...: i: int ...: In [3]: A(i='4.0') Out[3]: A(i=4) In [4]: A(i='-4.0') --------------------------------------------------------------------------- ValidationError Traceback (most recent call last) Cell In[4], line 1 ----> 1 A(i='-4.0') File ~/.cache/pypoetry/virtualenvs/hl-7m4wOqun-py3.12/lib/python3.12/site-packages/pydantic/main.py:176, in BaseModel.__init__(self, **data) 174 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks 175 __tracebackhide__ = True --> 176 self.__pydantic_validator__.validate_python(data, self_instance=self) ValidationError: 1 validation error for A i Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='-4.0', input_type=str] For further information visit https://errors.pydantic.dev/2.7/v/int_parsing

Minimal Reproduction

repro.py
pydantic version: 2.7.1 pydantic-core version: 2.18.2 pydantic-core build: profile=release pgo=true install path: /home/noam/.cache/pypoetry/virtualenvs/hl-7m4wOqun-py3.12/lib/python3.12/site-packages/pydantic python version: 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] platform: Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.39 related packages: typing_extensions-4.10.0 mypy-1.7.1 commit: unknown

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

Parsing negative integer strings results in validation errors, causing application crashes.

Why It Broke

The validation logic fails to handle the '-' character in negative integer strings

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 applied if the application relies on the previous validation behavior.

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

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 applied if the application relies on the previous validation behavior.

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.