-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
(Already being worked on)
Discussed in #14442
Originally posted by falkoschindler December 3, 2025
First Check
- I added a very descriptive title here.
- I used the GitHub search to find a similar question and didn't find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google "How to X in FastAPI" and didn't find any information.
- I already read and followed all the tutorial in the docs and didn't find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
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
Alyxion, tirkarthi, frankhuurman, rahmed-hartree, frank-lighten and 3 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working