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%.
@@ -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
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
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.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).
- 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
- GitHub issue: #9396
- Fix PR: https://github.com/pydantic/pydantic-core/pull/1291
- First fixed release: 1.10.1
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.39
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 ..”
“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…”
Failure Signature (Search String)
- In [1]: import pydantic
Error Message
Stack trace
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
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
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.
When NOT to Use This Fix
- This fix should not be applied if the application relies on the previous validation behavior.
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.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.