(Already being worked on)
Discussed in #14442
Originally posted by falkoschindler December 3, 2025
First Check
Commit to Help
Example Code
from functools import wraps
import uvicorn
from fastapi import FastAPI
app = FastAPI()
def my_decorator(func):
"""A decorator that wraps a sync function with an async handler."""
@wraps(func)
async def wrapper():
func()
return 'OK'
return wrapper
@app.get('/')
@my_decorator
def index():
"""A simple sync page function."""
print('Hello!')
if __name__ == '__main__':
uvicorn.run(app)
Description
- Visit "/".
- You'll see "Internal Server Error".
- A ValueError appears:
ValueError: [TypeError("'coroutine' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')]
Since FastAPI 0.123.5 (PR #14434), using functools.wraps on an async wrapper around a sync function causes FastAPI to incorrectly treat the handler as sync, resulting in: ValueError: [TypeError("'coroutine' object is not iterable"), ...]
The issue is that Dependant.is_coroutine_callable now uses inspect.unwrap() which follows __wrapped__ back to the original sync function, instead of checking if the actual registered handler is async.
Operating System
macOS
Operating System Details
No response
FastAPI Version
0.123.5
Pydantic Version
2.12.5
Python Version
3.11.11
Additional Context
No response
(Already being worked on)
Discussed in #14442
Originally posted by falkoschindler December 3, 2025
First Check
Commit to Help
Example Code
Description
Since FastAPI 0.123.5 (PR #14434), using
functools.wrapson an async wrapper around a sync function causes FastAPI to incorrectly treat the handler as sync, resulting in:ValueError: [TypeError("'coroutine' object is not iterable"), ...]The issue is that
Dependant.is_coroutine_callablenow usesinspect.unwrap()which follows__wrapped__back to the original sync function, instead of checking if the actual registered handler is async.Operating System
macOS
Operating System Details
No response
FastAPI Version
0.123.5
Pydantic Version
2.12.5
Python Version
3.11.11
Additional Context
No response