Jump to solution
Verify

The Fix

pip install pydantic==2.12.5

Based on closed pydantic/pydantic issue #12521 · 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
@@ -20,6 +20,7 @@ from typing import TYPE_CHECKING, Any, Generic, TypeVar, overload +from pydantic_core import MISSING from typing_extensions import TypeAlias, TypeGuard, deprecated
repro.py
# pydantic/_internal/_utils.py from pydantic_core import MISSING def smart_deepcopy(obj): if obj is MISSING: return obj # rest of current logic...
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.12.5\nWhen NOT to use: This fix should not be applied if the behavior of `__deepcopy__()` is expected to change.\n\n

Why This Fix Works in Production

  • Trigger: TypeError: Cannot pickle 'Sentinel' object.
  • Mechanism: Deep-copying the `MISSING` sentinel raises a TypeError due to its non-pickleable nature
  • Why the fix works: Special-cases the `MISSING` sentinel in `smart_deepcopy()` to avoid TypeError during deep-copying. (first fixed release: 2.12.5).
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

  • Deep-copying the `MISSING` sentinel raises a TypeError due to its non-pickleable nature
  • Surfaces as: TypeError: Cannot pickle 'Sentinel' object.

Proof / Evidence

Discussion

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

“A PR is welcomed but only to tweak smart_deepcopy(), I'd rather not change the current __deepcopy__() behavior”
@Viicos · 2025-11-11 · source
“This is expected, as per the documentation, PEP 661 sentinels aren't pickleable. We can update smart_deepcopy() to account for this in the meanwhile, but this…”
@Viicos · 2025-11-11 · source
“What do you think of my proposed tweak to smart_deepcopy()? And using smart_deepcopy() in .__deepcopy__()? @Viicos I'm happy to draft a PR :).”
@ornariece · 2025-11-11 · source

Failure Signature (Search String)

  • TypeError: Cannot pickle 'Sentinel' object.

Error Message

Stack trace
error.txt
Error Message ------------- TypeError: Cannot pickle 'Sentinel' object.

Minimal Reproduction

repro.py
# pydantic/_internal/_utils.py from pydantic_core import MISSING def smart_deepcopy(obj): if obj is MISSING: return obj # rest of current logic...

Environment

  • Pydantic: 2

What Broke

Attempts to deepcopy a model with `MISSING` results in a crash, causing application failures.

Why It Broke

Deep-copying the `MISSING` sentinel raises a TypeError due to its non-pickleable nature

Fix Options (Details)

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

pip install pydantic==2.12.5

When NOT to use: This fix should not be applied if the behavior of `__deepcopy__()` is expected to change.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/pydantic/pydantic/pull/12522

First fixed release: 2.12.5

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 behavior of `__deepcopy__()` is expected to change.

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.12.5 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.