Jump to solution
Verify

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

Jump to Verify Open PR/Commit
@@ -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__"]}.') ):
repro.py
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'>
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.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).
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

  • 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

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
affected (exit=None)
fixed (exit=0)

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”
@Viicos · 2025-04-28 · source
“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,…”
@karta9821 · 2025-04-27 · source
“@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.”
@Viicos · 2025-04-28 · source

Failure Signature (Search String)

  • Inconsistent Private Attribute Type
Copy-friendly signature
signature.txt
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.txt
Error Message ------------- @karta9821 I appreciate the help but this is a genuine bug and what you stated is also incorrect.

Minimal Reproduction

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

When NOT to use: This fix should not be used if private attributes are intended to remain inaccessible.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if private attributes are intended to remain inaccessible.

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