Jump to solution
Verify

The Fix

pip install pydantic==2.11.5

Based on closed pydantic/pydantic issue #11805 · 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
@@ -4,6 +4,7 @@ import ast import inspect +import sys import textwrap from typing import Any
repro.py
class Model(BaseModel, use_attribute_docstrings=True): x: list[str] | None '''this is x''' print('Model schema') print(Model.model_json_schema()) # wrong docstring import pydantic._internal._fields from pydantic._internal._fields import _update_fields_from_docstrings from functools import partial pydantic._internal._fields._update_fields_from_docstrings = partial( _update_fields_from_docstrings, use_inspect=True ) # inject del Model class Model(BaseModel, use_attribute_docstrings=True): x: list[str]|None '''this is x''' print('Model schema after injecting `_update_fields_from_docstrings`') print(Model.model_json_schema()) # now fixed
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.5\nWhen NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.\n\n

Why This Fix Works in Production

  • Trigger: when `use_attribute_docstrings=True`, `DocstringVisitor` fail to grab field docs in unknown reason when using
  • Mechanism: The issue arises from the failure to retrieve field docstrings due to improper source extraction logic
  • Why the fix works: Ensures that `inspect.getsourcelines()` is used for docstring extraction on Python 3.13 and greater, fixing issues with field docstrings not being retrieved correctly. (first fixed release: 2.11.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

  • Shows up under Python 3.13 in real deployments (not just unit tests).
  • The issue arises from the failure to retrieve field docstrings due to improper source extraction logic
  • Production symptom (often without a traceback): when `use_attribute_docstrings=True`, `DocstringVisitor` fail to grab field docs in unknown reason when using

Proof / Evidence

Discussion

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

“The default use_attribute_docstrings behavior is to extract the docstrings by walking up the frames from the call stack”
@Viicos · 2025-04-29 · source
“Here is a MRE: proj structure: in __init__.py: in test.py:”
@92MING · 2025-04-29 · source
“I wouldn't expect things to work correctly if you are manually modifying such dunder attributes”
@Viicos · 2025-05-02 · source
“> The default use_attribute_docstrings behavior is to extract the docstrings by walking up the frames from the call stack”
@92MING · 2025-04-29 · source

Failure Signature (Search String)

  • when `use_attribute_docstrings=True`, `DocstringVisitor` fail to grab field docs in unknown reason when using
  • print(Model.model_json_schema())
Copy-friendly signature
signature.txt
Failure Signature ----------------- when `use_attribute_docstrings=True`, `DocstringVisitor` fail to grab field docs in unknown reason when using print(Model.model_json_schema())

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- when `use_attribute_docstrings=True`, `DocstringVisitor` fail to grab field docs in unknown reason when using print(Model.model_json_schema())

Minimal Reproduction

repro.py
class Model(BaseModel, use_attribute_docstrings=True): x: list[str] | None '''this is x''' print('Model schema') print(Model.model_json_schema()) # wrong docstring import pydantic._internal._fields from pydantic._internal._fields import _update_fields_from_docstrings from functools import partial pydantic._internal._fields._update_fields_from_docstrings = partial( _update_fields_from_docstrings, use_inspect=True ) # inject del Model class Model(BaseModel, use_attribute_docstrings=True): x: list[str]|None '''this is x''' print('Model schema after injecting `_update_fields_from_docstrings`') print(Model.model_json_schema()) # now fixed

Environment

  • Python: 3.13
  • Pydantic: 2

What Broke

Field docstrings are not retrieved, leading to incorrect model schema generation.

Why It Broke

The issue arises from the failure to retrieve field docstrings due to improper source extraction logic

Fix Options (Details)

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

pip install pydantic==2.11.5

When NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.

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

First fixed release: 2.11.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

  • Do not use if it changes public behavior or if the failure cannot be reproduced.

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

Related Issues

No related fixes found.

Sources

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