Jump to solution
Verify

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

Jump to Verify Open PR/Commit
@@ -277,10 +277,16 @@ def get_function_type_hints( copes with `partial`. """ - if isinstance(function, partial): - annotations = function.func.__annotations__ - else:
repro.py
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"] = }')
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==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).
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.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

Discussion

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

“@aphedges, Thanks for the report”
@sydney-runkle · 2024-03-12 · source

Failure Signature (Search String)

  • class Demo(BaseModel):

Error Message

Stack trace
error.txt
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

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

When NOT to use: This fix should not be used if the callable requires specific annotations.

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.

When NOT to use: This fix should not be used if the callable requires specific annotations.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if the callable requires specific annotations.

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