The Fix
Updates the documentation for `use_attribute_docstrings` to clarify its limitations in the interactive interpreter.
Based on closed pydantic/pydantic issue #12651 · 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%.
@@ -1038,7 +1038,7 @@ class Model(BaseModel):
# > Description in Field
```
- This requires the source code of the class to be available at runtime.
+ This requires the source code of the class to be available at runtime (and so won't work in the interactive interpreter shell).
from pydantic import BaseModel, ConfigDict, Field
class Model(BaseModel):
model_config = ConfigDict(use_attribute_docstrings=True)
x: str
"""
Example of an attribute docstring
"""
y: int = Field(description="Description in Field")
"""
Description in Field overrides attribute docstring
"""
print(Model.model_fields["x"].description)
# > Example of an attribute docstring
print(Model.model_fields["y"].description)
# > Description in Field
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Apply the official fix\nUpdates the documentation for `use_attribute_docstrings` to clarify its limitations in the interactive interpreter.\nWhen NOT to use: This fix is not applicable if the source code is not available at runtime.\n\n
Why This Fix Works in Production
- Trigger: Running the example code from the [docs](https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.use_attribute_docstrings) on the interpreter…
- Mechanism: The interactive interpreter does not retain the source code of the class at runtime
- 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.14 in real deployments (not just unit tests).
- The interactive interpreter does not retain the source code of the class at runtime
- Production symptom (often without a traceback): Python 3.14 does not support use_attribute_docstring
Proof / Evidence
- GitHub issue: #12651
- Fix PR: https://github.com/pydantic/pydantic/pull/12652
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.80
- 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).
“This is expected: > This requires the source code of the class to be available at runtime.”
Failure Signature (Search String)
- Running the example code from the [docs](https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.use_attribute_docstrings) on the interpreter does not yield the
Copy-friendly signature
Failure Signature
-----------------
Python 3.14 does not support use_attribute_docstring
Running the example code from the [docs](https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.use_attribute_docstrings) on the interpreter does not yield the same result, shown below.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Python 3.14 does not support use_attribute_docstring
Running the example code from the [docs](https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.use_attribute_docstrings) on the interpreter does not yield the same result, shown below.
Minimal Reproduction
from pydantic import BaseModel, ConfigDict, Field
class Model(BaseModel):
model_config = ConfigDict(use_attribute_docstrings=True)
x: str
"""
Example of an attribute docstring
"""
y: int = Field(description="Description in Field")
"""
Description in Field overrides attribute docstring
"""
print(Model.model_fields["x"].description)
# > Example of an attribute docstring
print(Model.model_fields["y"].description)
# > Description in Field
Environment
- Python: 3.14
- Pydantic: 2
What Broke
Users experience incorrect descriptions when using attribute docstrings in interactive sessions.
Why It Broke
The interactive interpreter does not retain the source code of the class at runtime
Fix Options (Details)
Option A — Apply the official fix
Updates the documentation for `use_attribute_docstrings` to clarify its limitations in the interactive interpreter.
Fix reference: https://github.com/pydantic/pydantic/pull/12652
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not applicable if the source code is not available at runtime.
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 |
|---|---|
| 6.12.57 | Broken |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.