The Fix
pip install pydantic==1.10.15
Based on closed pydantic/pydantic issue #8967 · 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%.
@@ -277,10 +277,16 @@ def get_function_type_hints(
copes with `partial`.
"""
- if isinstance(function, partial):
- annotations = function.func.__annotations__
- else:
from typing import Annotated
from pydantic import BaseModel, HttpUrl, PlainSerializer
class Demo(BaseModel):
# Commented-out line below works
# url: Annotated[HttpUrl, PlainSerializer(lambda x: str(x))]
url: Annotated[HttpUrl, PlainSerializer(str)]
input_json = {"url": "https://github.com/pydantic/pydantic"}
obj = Demo.parse_obj(input_json)
assert isinstance(obj.model_dump()["url"], str), obj.model_dump()["url"]
print(f'{obj.model_dump()["url"] = }')
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==1.10.15\nWhen NOT to use: This fix should not be used if the callable requires specific annotations.\n\nOption C — Workaround\nwe should use for those stdlib callable types, though.\nWhen NOT to use: This fix should not be used if the callable requires specific annotations.\n\n
Why This Fix Works in Production
- Trigger: class Demo(BaseModel):
- Mechanism: The built-in callable `str` lacks an `__annotations__` attribute, causing issues with `PlainSerializer`
- Why the fix works: Fixes the issue where built-in callables like `str` cannot be used as arguments to `PlainSerializer`. (first fixed release: 1.10.15).
- 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.11 in real deployments (not just unit tests).
- The built-in callable `str` lacks an `__annotations__` attribute, causing issues with `PlainSerializer`
- Surfaces as: Traceback (most recent call last):
Proof / Evidence
- GitHub issue: #8967
- Fix PR: https://github.com/pydantic/pydantic/pull/9031
- First fixed release: 1.10.15
- 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.40
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@aphedges, Thanks for the report”
Failure Signature (Search String)
- class Demo(BaseModel):
Error Message
Stack trace
Error Message
-------------
Traceback (most recent call last):
File "/Users/ahedges/Downloads/demo.py", line 6, in <module>
class Demo(BaseModel):
File "/Users/ahedges/.pyenv/versions/biomed/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 183, in __new__
complete_model_class(
File "/Users/ahedges/.pyenv/versions/biomed/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 517, in complete_model_class
schema = cls.__get_pydantic_core_schema__(cls, handler)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahedges/.pyenv/versions/biomed/lib/python3.11/site-packages/pydantic/main.py", line 584, in __get_pydantic_core_schema__
return __handler(__source)
^^^^^^^^^^^^^^^^^^^
File "/Users/ahedges/.pyenv/versions/biomed/lib/python3.11/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
schema = self._handler(__source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahedges/.pyenv/versions/biomed/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 499, in generate_schema
schema = self._generate_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ahedges/.pyenv/versions/biomed/lib/python3.11/site-packages/pydantic/_internal/_generate_schema.py", line 737, in _generate_schema
schema = self._post_process_gener
... (truncated) ...
Minimal Reproduction
from typing import Annotated
from pydantic import BaseModel, HttpUrl, PlainSerializer
class Demo(BaseModel):
# Commented-out line below works
# url: Annotated[HttpUrl, PlainSerializer(lambda x: str(x))]
url: Annotated[HttpUrl, PlainSerializer(str)]
input_json = {"url": "https://github.com/pydantic/pydantic"}
obj = Demo.parse_obj(input_json)
assert isinstance(obj.model_dump()["url"], str), obj.model_dump()["url"]
print(f'{obj.model_dump()["url"] = }')
Environment
- Python: 3.11
- Pydantic: 2
What Broke
Using built-in callables like `str` leads to exceptions when passed to `PlainSerializer`.
Why It Broke
The built-in callable `str` lacks an `__annotations__` attribute, causing issues with `PlainSerializer`
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.15
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Option C — Workaround Temporary workaround
we should use for those stdlib callable types, though.
Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.
Fix reference: https://github.com/pydantic/pydantic/pull/9031
First fixed release: 1.10.15
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the callable requires specific annotations.
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 |
|---|---|
| 1.10.15 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.