The Fix
pip install pydantic==2.11.4
Based on closed pydantic/pydantic issue #11797 · 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%.
@@ -406,7 +406,7 @@ def inspect_namespace( # noqa C901
and value.__module__ == namespace['__module__']
and '__qualname__' in namespace
- and value.__qualname__.startswith(namespace['__qualname__'])
+ and value.__qualname__.startswith(f'{namespace["__qualname__"]}.')
):
from enum import Enum
from pydantic import BaseModel
class HMSTablePrivilege(str, Enum):
ALL_PRIVILEGES = "ALL PRIVILEGES"
class HMSTable(BaseModel):
_grantable_privileges: Enum = HMSTablePrivilege
HMSTable._grantable_privileges
# <enum 'HMSTablePrivilege'>
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.11.4\nWhen NOT to use: This fix should not be used if private attributes are intended to remain inaccessible.\n\n
Why This Fix Works in Production
- Trigger: Inconsistent Private Attribute Type
- Mechanism: The qualified name comparison of private attributes during namespace inspection was incorrect
- Why the fix works: Fixes the qualified name comparison of private attributes during namespace inspection, addressing the inconsistency in private attribute types. (first fixed release: 2.11.4).
- 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
- The qualified name comparison of private attributes during namespace inspection was incorrect
- Production symptom (often without a traceback): @karta9821 I appreciate the help but this is a genuine bug and what you stated is also incorrect.
Proof / Evidence
- GitHub issue: #11797
- Fix PR: https://github.com/pydantic/pydantic/pull/11803
- First fixed release: 2.11.4
- 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.64
Verified Execution
We executed the runnable minimal repro in a temporary environment and captured exit codes + logs.
- Status: PASS
- Ran: 2026-02-11T16:52:29Z
- Package: pydantic
- Fixed: 2.11.4
- Mode: fixed_only
- Outcome: ok
Logs
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@karta9821 I appreciate the help but this is a genuine bug and what you stated is also incorrect. Offending code: https://github.com/pydantic/pydantic/blob/bf068661cf3fdadb93881762abe6fdc8a2592966/pydantic/_internal/_model_construction.py#L405-L412”
“This is working as intended: Pydantic treats any attribute starting with an underscore as a private attribute, so it’s excluded entirely from schema generation, validation,…”
“@xinyang-zhu, note that we recommend inspecting private attributes using the __private_attributes__ class attribute. Trying to access by attribute name isn't explicitly supported.”
Failure Signature (Search String)
- Inconsistent Private Attribute Type
Copy-friendly signature
Failure Signature
-----------------
@karta9821 I appreciate the help but this is a genuine bug and what you stated is also incorrect.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
@karta9821 I appreciate the help but this is a genuine bug and what you stated is also incorrect.
Minimal Reproduction
from enum import Enum
from pydantic import BaseModel
class HMSTablePrivilege(str, Enum):
ALL_PRIVILEGES = "ALL PRIVILEGES"
class HMSTable(BaseModel):
_grantable_privileges: Enum = HMSTablePrivilege
HMSTable._grantable_privileges
# <enum 'HMSTablePrivilege'>
Environment
- Pydantic: 2
What Broke
Private attributes were inconsistently reported, leading to confusion in attribute access.
Why It Broke
The qualified name comparison of private attributes during namespace inspection was incorrect
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.11.4
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/11803
First fixed release: 2.11.4
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if private attributes are intended to remain inaccessible.
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.11.4 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.