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.
I have a fastapi example running with your library, I like the clean architecture. However, what is the best way to handle exceptions during dependency resolution? At the moment my FastAPI hangs and does not even return a 500.
The text was updated successfully, but these errors were encountered:
I use poetry, dependency-injector is installed with 4.27.0. Here is my terminal output after doing a GET request to http://127.0.0.1:8000/listener/. The exception that I raise for testing is raised. I would expect that dependency-injector passes this exception to fastapi and fastapi handles it, resulting an a 500 being returned. Instead the request hangs.
% poetry run uvicorn api.main:app
INFO: Started server process 
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Exception in callback Dependency._async_provide(<Future pendi...tasks.py:758]>)(<Future finis...n=Exception()>)
handle: <Handle Dependency._async_provide(<Future pendi...tasks.py:758]>)(<Future finis...n=Exception()>)>
Traceback (most recent call last):
File "/usr/local/Cellarfirstname.lastname@example.org/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/events.py", line 81, in _run
File "src/dependency_injector/providers.pyx", line 767, in dependency_injector.providers.Dependency._async_provide
File "src/dependency_injector/providers.pyx", line 2652, in dependency_injector.providers.BaseSingleton._async_init_instance
File "src/dependency_injector/providers.pxd", line 566, in dependency_injector.providers.__async_call_callback
File "src/dependency_injector/providers.pxd", line 458, in dependency_injector.providers.__async_prepare_args_kwargs_callback
File "src/dependency_injector/providers.pyx", line 3489, in dependency_injector.providers.Resource._async_init_callback
File "./api/gateways/redis.py", line 6, in init_redis
Thank you for the traceback and test case. There were similar issues in asynchronous mode before. I thought I fixed all of them in 4.23.2 and 4.23.3, but looks like there are still some issues. I'll take a look and get back to you.
I believe I'm running into this issue. I have a Resource that calls an async init function. The function raises an exception and my app hangs indefinitely. I can create a separate ticket for this issue if desired but it seems to be similar to what @wackazong mentioned. I'm running with version 4.40.0.