New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
functools.partial() does not work on an async dependable #10720
Comments
I understand that using an asynchronous function without |
In my opinion,in FastAPI, dependency functions are automatically executed with await added. |
@Kludex it works as expected with async def dep1(
n: int = Depends(the_answer),
):
yield n + 1 Output 1: @app.get("/")
def main(
d1=Depends(partial(dep1)),
):
print(d1) # prints 43
return {} Output 2: @app.get("/")
def main(
d1=Depends(partial(dep1, n=10)),
):
print(d1) # prints 11
return {} |
Discussed in #9744
Originally posted by lieryan June 26, 2023
First Check
Commit to Help
Example Code
Description
I would've expected
d1
above to be the return value of the dependable, but it seems like fastapi didn't identify the partial as an coroutine function and instead passed the unawaited coroutine into the view function.inspect.iscoroutinefunction()
andinspect.signature()
were able to deconstruct the partial object to correctly identify whether a partial contains a coroutine or a regular function, so it seems like it should've been possible for FastAPI to use handle partial correctly:Operating System
Linux
Operating System Details
No response
FastAPI Version
0.98.0
Python Version
Python 3.10.6
Additional Context
No response
The text was updated successfully, but these errors were encountered: