The Fix
pip install pydantic==2.7.2
Based on closed pydantic/pydantic issue #9234 · 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%.
@@ -33,12 +33,14 @@
from ..fields import Field as PydanticModelField
from ..fields import FieldInfo, ModelPrivateAttr
+ from ..fields import PrivateAttr as PydanticModelPrivateAttr
from ..main import BaseModel
else:
pydantic version: 2.7.0
pydantic-core version: 2.18.1
pydantic-core build: profile=release pgo=true
install path: C:\Users\none\AppData\Roaming\Python\Python312\site-packages\pydantic
python version: 3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)]
platform: Windows-10-10.0.19045-SP0
related packages: fastapi-0.109.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.7.2\nWhen NOT to use: This fix should not be applied if backward compatibility is a priority.\n\n
Why This Fix Works in Production
- Trigger: Though I think this is a not-so-good idea and the change should break compatibility in favor of better interface and less unclear behavior.
- Mechanism: Private attributes were included in the constructor, leading to confusion in type checkers
- Why the fix works: Hides private attributes (`PrivateAttr`) from the `__init__` signature in type checkers, addressing issue #9234. (first fixed release: 2.7.2).
- 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
- Private attributes were included in the constructor, leading to confusion in type checkers
- Production symptom (often without a traceback): Though I think this is a not-so-good idea and the change should break compatibility in favor of better interface and less unclear behavior.
Proof / Evidence
- GitHub issue: #9234
- Fix PR: https://github.com/pydantic/pydantic/pull/9293
- First fixed release: 2.7.2
- 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.54
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Hello, I just encountered the same bug, but using dataclass from pydantic.dataclasses”
“Hi @idan22moral, Thanks for looking into this with backwards compatibility in mind! Will take a look at your PR here shortly. Curious to hear what…”
“@idan22moral, Thanks for the proposal here”
“Thanks for your answer, @sydney-runkle 😊 I've dug further into it, and it seems that besides the fact that pydantic allows private attributes in the…”
Failure Signature (Search String)
- Though I think this is a not-so-good idea and the change should break compatibility in favor of better interface and less unclear behavior.
- According to the definition of [runtime behavior](https://typing.readthedocs.io/en/latest/spec/dataclasses.html#runtime-behavior) of `dataclass_transform` and the fact that
Copy-friendly signature
Failure Signature
-----------------
Though I think this is a not-so-good idea and the change should break compatibility in favor of better interface and less unclear behavior.
According to the definition of [runtime behavior](https://typing.readthedocs.io/en/latest/spec/dataclasses.html#runtime-behavior) of `dataclass_transform` and the fact that Pydantic does not use `__dataclass_transform__`,
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Though I think this is a not-so-good idea and the change should break compatibility in favor of better interface and less unclear behavior.
According to the definition of [runtime behavior](https://typing.readthedocs.io/en/latest/spec/dataclasses.html#runtime-behavior) of `dataclass_transform` and the fact that Pydantic does not use `__dataclass_transform__`,
Minimal Reproduction
pydantic version: 2.7.0
pydantic-core version: 2.18.1
pydantic-core build: profile=release pgo=true
install path: C:\Users\none\AppData\Roaming\Python\Python312\site-packages\pydantic
python version: 3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)]
platform: Windows-10-10.0.19045-SP0
related packages: fastapi-0.109.0 typing_extensions-4.9.0
commit: unknown
Environment
- Pydantic: 2
What Broke
Users experienced unclear constructor signatures when using private attributes.
Why It Broke
Private attributes were included in the constructor, leading to confusion in type checkers
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.7.2
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Option D — Guard side-effects with OnceOnly Guardrail for side-effects
Mitigate duplicate external side-effects under retries/timeouts/agent loops by gating the operation before calling external systems.
- Place OnceOnly between your code/agent and real side-effects (Stripe, emails, CRM, APIs).
- Use a stable key per side-effect (e.g., customer_id + action + idempotency_key).
- Fail-safe: configure fail-open vs fail-closed based on blast radius and spend risk.
Show example snippet (optional)
from onceonly import OnceOnly
import os
once = OnceOnly(api_key=os.environ["ONCEONLY_API_KEY"], fail_open=True)
# Stable idempotency key per real side-effect.
# Use a request id / job id / webhook delivery id / Stripe event id, etc.
event_id = "evt_..." # replace
key = f"stripe:webhook:{event_id}"
res = once.check_lock(key=key, ttl=3600)
if res.duplicate:
return {"status": "already_processed"}
# Safe to execute the side-effect exactly once.
handle_event(event_id)
Fix reference: https://github.com/pydantic/pydantic/pull/9293
First fixed release: 2.7.2
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if backward compatibility is a priority.
- Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.
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.7.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.