The Fix
pip install pydantic==2.8.0
Based on closed pydantic/pydantic issue #9748 · 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%.
@@ -38,6 +38,7 @@
FLOAT_CONSTRAINTS = {*NUMERIC_CONSTRAINTS, *STRICT}
+DECIMAL_CONSTRAINTS = {'max_digits', 'decimal_places', *FLOAT_CONSTRAINTS}
INT_CONSTRAINTS = {*NUMERIC_CONSTRAINTS, *STRICT}
BOOL_CONSTRAINTS = STRICT
pydantic version: 2.7.4
pydantic-core version: 2.18.4
pydantic-core build: profile=release pgo=false
install path: /Users/XXX/miniconda3/envs/py311/lib/python3.11/site-packages/pydantic
python version: 3.11.5 (main, Sep 11 2023, 08:19:27) [Clang 14.0.6 ]
platform: macOS-10.16-x86_64-i386-64bit
related packages: fastapi-0.105.0 typing_extensions-4.9.0
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==2.8.0\nWhen NOT to use: This fix is not applicable if the constraints are not required for Decimal types.\n\nOption C — Workaround\nThe current workaround is to apply constraints directly to `Decimal`:\nWhen NOT to use: This fix is not applicable if the constraints are not required for Decimal types.\n\n
Why This Fix Works in Production
- Trigger: Currently, the following code raises a `ValueError`:
- Mechanism: The `max_digits` constraint is not recognized for `Optional[Decimal]` types
- Why the fix works: Adds a new constant `DECIMAL_CONSTRAINTS` into `pydantic/_internal/_known_annotated_metadata.py`, allowing field constraints to be automatically applied to the inner `Decimal` types of an `Optional[Decimal]` type. (first fixed release: 2.8.0).
- 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.11 in real deployments (not just unit tests).
- The `max_digits` constraint is not recognized for `Optional[Decimal]` types
- Production symptom (often without a traceback): Currently, the following code raises a `ValueError`:
Proof / Evidence
- GitHub issue: #9748
- Fix PR: https://github.com/pydantic/pydantic/pull/9754
- First fixed release: 2.8.0
- 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.61
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@lazyhope, Feel free to submit a PR, I'd be happy to review. Thanks for outlining the issue so clearly + citing other relevant discussions from…”
“> @lazyhope, > > Feel free to submit a PR, I'd be happy to review. Thanks for outlining the issue so clearly + citing other…”
Failure Signature (Search String)
- Currently, the following code raises a `ValueError`:
- I am interested in hearing your thoughts on this proposal and would be willing to submit a PR if this change is acceptable.
Copy-friendly signature
Failure Signature
-----------------
Currently, the following code raises a `ValueError`:
I am interested in hearing your thoughts on this proposal and would be willing to submit a PR if this change is acceptable.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Currently, the following code raises a `ValueError`:
I am interested in hearing your thoughts on this proposal and would be willing to submit a PR if this change is acceptable.
Minimal Reproduction
pydantic version: 2.7.4
pydantic-core version: 2.18.4
pydantic-core build: profile=release pgo=false
install path: /Users/XXX/miniconda3/envs/py311/lib/python3.11/site-packages/pydantic
python version: 3.11.5 (main, Sep 11 2023, 08:19:27) [Clang 14.0.6 ]
platform: macOS-10.16-x86_64-i386-64bit
related packages: fastapi-0.105.0 typing_extensions-4.9.0
commit: unknown
Environment
- Python: 3.11
- Pydantic: 2
What Broke
Code raises a ValueError when using constraints on Optional Decimal types.
Why It Broke
The `max_digits` constraint is not recognized for `Optional[Decimal]` types
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.8.0
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Option C — Workaround Temporary workaround
The current workaround is to apply constraints directly to `Decimal`:
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/9754
First fixed release: 2.8.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not applicable if the constraints are not required for Decimal types.
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 |
|---|---|
| 2.8.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.