Jump to solution
Verify

The Fix

pip install pydantic==2.10

Based on closed pydantic/pydantic issue #10771 · 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
@@ -146,7 +146,8 @@ def __init__(__dataclass_self__: PydanticDataclass, *args: Any, **kwargs: Any) - init=original_init, fields=cls.__pydantic_fields__, # type: ignore - config_wrapper=config_wrapper, + populate_by_name=config_wrapper.populate_by_name, + extra=config_wrapper.extra,
repro.py
from typing import Any from pydantic import BaseModel from openai import OpenAI class Spacex(BaseModel): client: Any = OpenAI(api_key='11') c = Spacex()
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.10\nWhen NOT to use: This fix is not suitable for models that require deep copying of mutable default values.\n\n

Why This Fix Works in Production

  • Trigger: class Spacex(BaseModel):
  • Mechanism: The issue arises from deep copying default values during model signature generation
  • Why the fix works: Makes the `__signature__` a lazy property and avoids deep copying defaults, addressing the issue with default values failing during model signature generation. (first fixed release: 2.10).
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 issue arises from deep copying default values during model signature generation
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

Discussion

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

“@linpan, This will be fixed in 2.10”
@Viicos · 2024-11-18 · confirmation · source
“@sydney-runkle I think I see what's wrong, I'll investigate further”
@Viicos · 2024-11-07 · source
“Please provide a complete traceback (avoiding screenshots) and if possible a MRE.”
@Viicos · 2024-11-06 · source
“Happy to reopen when we get the above ^^”
@sydney-runkle · 2024-11-06 · source

Failure Signature (Search String)

  • class Spacex(BaseModel):

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "/Users/hiro/PycharmProjects/o1-engineer/GPR.py", line 7, in <module> class Spacex(BaseModel): File "/Users/hiro/PycharmProjects/o1-engineer/.venv/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 224, in __new__ complete_model_class( File "/Users/hiro/PycharmProjects/o1-engineer/.venv/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 610, in complete_model_class generate_pydantic_signature(init=cls.__init__, fields=cls.model_fields, config_wrapper=config_wrapper), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hiro/PycharmProjects/o1-engineer/.venv/lib/python3.11/site-packages/pydantic/_internal/_signature.py", line 159, in generate_pydantic_signature merged_params = _generate_signature_parameters(init, fields, config_wrapper) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hiro/PycharmProjects/o1-engineer/.venv/lib/python3.11/site-packages/pydantic/_internal/_signature.py", line 115, in _generate_signature_parameters kwargs = {} if field.is_required() else {'default': field.get_default(call_default_factory=False)} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/hiro/P ... (truncated) ...

Minimal Reproduction

repro.py
from typing import Any from pydantic import BaseModel from openai import OpenAI class Spacex(BaseModel): client: Any = OpenAI(api_key='11') c = Spacex()

Environment

  • Python: 3.11
  • Pydantic: 2

What Broke

Users experience failures when instantiating models with default values, leading to runtime errors.

Why It Broke

The issue arises from deep copying default values during model signature generation

Fix Options (Details)

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

pip install pydantic==2.10

When NOT to use: This fix is not suitable for models that require deep copying of mutable default values.

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

First fixed release: 2.10

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 suitable for models that require deep copying of mutable default values.

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

Related Issues

No related fixes found.

Sources

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