You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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() and inspect.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:
In [5]: def regular(a, b): pass
In [6]: async def coro(a, b): pass
In [7]: inspect.iscoroutinefunction(partial(regular, 1))
Out[7]: False
In [8]: inspect.iscoroutinefunction(partial(coro, 1))
Out[8]: True
In [20]: inspect.signature(partial(coro, 1))
Out[20]: <Signature (b)>
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:
I understand that using an asynchronous function without await in a synchronous function will naturally result in a coroutine object. Could you please clarify the intention behind your question? It seems evident that this behavior is expected in Python's asynchronous programming model.
I understand that using an asynchronous function without await in a synchronous function will naturally result in a coroutine object. Could you please clarify the intention behind your question? It seems evident that this behavior is expected in Python's asynchronous programming model.
In my opinion,in FastAPI, dependency functions are automatically executed with await added.
This is based on the documentation
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: