The Fix
pip install pydantic==1.10.19
Based on closed pydantic/pydantic issue #10228 · 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%.
@@ -88,7 +88,7 @@ def display_as_type(obj: Any) -> str:
Takes some logic from `typing._type_repr`.
"""
- if isinstance(obj, types.FunctionType):
+ if isinstance(obj, (types.FunctionType, types.BuiltinFunctionType)):
return obj.__name__
from pydantic import BaseModel
from typing import Any, Callable
from types import FunctionType
import inspect
import time
# Current Issue
print(isinstance(time.time_ns, FunctionType))
# > False
# Suggested Fix
def is_function(obj: Any) -> bool:
return inspect.isfunction(obj) or inspect.isbuiltin(obj) or inspect.isroutine(obj) or inspect.ismethod(obj)
print(is_function(time.time_ns))
# > True
# Prettier Function Representation
class Dummy(BaseModel):
def foo(self) -> None: ...
@staticmethod
def local_bar() -> Callable[[], None]:
def bar() -> None: ...
return bar
def current_function_repr(obj: Any) -> str:
return obj.__name__
def prettier_function_repr(obj: Any) -> str:
# If function is locally defined use __name__ instead of __qualname__
return obj.__name__ if '<locals>' in obj.__qualname__ else obj.__qualname__
print(current_function_repr(Dummy.foo))
# > foo
print(prettier_function_repr(Dummy.foo))
# > Dummy.foo
print(current_function_repr(Dummy.local_bar()))
# > bar
print(prettier_function_repr(Dummy.local_bar()))
# > bar
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.19\nWhen NOT to use: Do not apply this fix if performance is a critical concern in your application.\n\n
Why This Fix Works in Production
- Trigger: In [1]: from types import BuiltinFunctionType, FunctionType
- Mechanism: The internal representation of function types fails for some built-in functions due to incorrect type checking
- Why the fix works: Fixes representation of builtin function types evaluated in the display_as_type function. (first fixed release: 1.10.19).
- 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.12 in real deployments (not just unit tests).
- The internal representation of function types fails for some built-in functions due to incorrect type checking
- Surfaces as: In [1]: from types import BuiltinFunctionType, FunctionType
Proof / Evidence
- GitHub issue: #10228
- Fix PR: https://github.com/pydantic/pydantic/pull/10479
- First fixed release: 1.10.19
- 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.34
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@sydney-runkle, I limited the fix to only identifying builtin function types as suggested by @mpkocher”
“@kschwab, Thanks for reporting this”
“Maybe using types.BuiltinFunctionType and/or other related types defined there could help? https://docs.python.org/3/library/types.html#types.BuiltinFunctionType”
“@mpkocher that's a cleaner fix 👍🏾 I probably won't get to this until sometime next week. Feel free to throw something up sooner if you…”
Failure Signature (Search String)
- In [1]: from types import BuiltinFunctionType, FunctionType
Error Message
Stack trace
Error Message
-------------
In [1]: from types import BuiltinFunctionType, FunctionType
In [2]: import time
In [3]: isinstance(time.time_ns, (BuiltinFunctionType, FunctionType))
Out[3]: True
In [4]: time.time_ns.__name__
Out[4]: 'time_ns'
In [5]: isinstance(len, (BuiltinFunctionType, FunctionType))
Out[5]: True
In [6]: def fx(a, b): return a + b
In [7]: isinstance(fx, (BuiltinFunctionType, FunctionType))
Out[7]: True
In [8]: from functools import partial
In [9]: f1 = partial(fx, 1)
In [10]: isinstance(f1, (BuiltinFunctionType, FunctionType))
Out[10]: False
In [11]: f1.__name__
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[11], line 1
----> 1 f1.__name__
AttributeError: 'functools.partial' object has no attribute '__name__'
Minimal Reproduction
from pydantic import BaseModel
from typing import Any, Callable
from types import FunctionType
import inspect
import time
# Current Issue
print(isinstance(time.time_ns, FunctionType))
# > False
# Suggested Fix
def is_function(obj: Any) -> bool:
return inspect.isfunction(obj) or inspect.isbuiltin(obj) or inspect.isroutine(obj) or inspect.ismethod(obj)
print(is_function(time.time_ns))
# > True
# Prettier Function Representation
class Dummy(BaseModel):
def foo(self) -> None: ...
@staticmethod
def local_bar() -> Callable[[], None]:
def bar() -> None: ...
return bar
def current_function_repr(obj: Any) -> str:
return obj.__name__
def prettier_function_repr(obj: Any) -> str:
# If function is locally defined use __name__ instead of __qualname__
return obj.__name__ if '<locals>' in obj.__qualname__ else obj.__qualname__
print(current_function_repr(Dummy.foo))
# > foo
print(prettier_function_repr(Dummy.foo))
# > Dummy.foo
print(current_function_repr(Dummy.local_bar()))
# > bar
print(prettier_function_repr(Dummy.local_bar()))
# > bar
Environment
- Python: 3.12
- Pydantic: 2
What Broke
Users experience incorrect type representations for built-in functions in settings.
Why It Broke
The internal representation of function types fails for some built-in functions due to incorrect type checking
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.19
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/10479
First fixed release: 1.10.19
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not apply this fix if performance is a critical concern in your application.
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.19 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.