Jump to solution
Verify

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%.

Jump to Verify Open PR/Commit
@@ -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
repro.py
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
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==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).
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.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

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…”
@sydney-runkle · 2024-06-25 · source
“> @lazyhope, > > Feel free to submit a PR, I'd be happy to review. Thanks for outlining the issue so clearly + citing other…”
@lazyhope · 2024-06-25 · source

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
signature.txt
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.txt
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

repro.py
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

When NOT to use: This fix is not applicable if the constraints are not required for Decimal types.

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`:

When NOT to use: This fix is not applicable if the constraints are not required for Decimal types.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if the constraints are not required for Decimal 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
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.