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 have an application which uses heavily nested dependencies. Many of those dependencies have validation logic which throws HTTPExceptions so that users can update their requests and try again.
I am upgrading this from Starlite v1 and have hit an issue with how dependencies are handled when nesting occurs. It appears nested dependencies are processed concurrently within an anyio.TaskGroup instance. If any exception occurs in This instance of create_task_group, they all result in a GroupException. Because of this, any HTTPExceptions thrown from inside the dependency logic gets yeeted into the void and the requester never sees it.
ERROR - 2023-11-01 15:58:04,508 - litestar - config - exception raised on http connection to route /
+ Exception Group Traceback (most recent call last):
| File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/middleware/exceptions/middleware.py", line 191, in __call__
| await self.app(scope, receive, send)
| File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/routes/http.py", line 81, in handle
| response = await self._get_response_for_request(
| File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/routes/http.py", line 133, in _get_response_for_request
|return await self._call_handler_function(
| File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/routes/http.py", line 153, in _call_handler_function
| response_data, cleanup_group = await self._get_response_data(
| File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/routes/http.py", line 185, in _get_response_data
| cleanup_group = await parameter_model.resolve_dependencies(request, kwargs)
| File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/_kwargs/kwargs_model.py", line 393, in resolve_dependencies
| async with create_task_group() as task_group:
| File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 664, in __aexit__
| raise BaseExceptionGroup(
| exceptiongroup.ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/_kwargs/dependencies.py", line 66, in resolve_dependency
| value = await dependency.provide(**dependency_kwargs)
| File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/di.py", line 84, in __call__
| value = self.dependency.value(**kwargs)
| File "/tmp/litestarTest/di_test_app.py", line 8, in get_dependency_child1
| raise HTTPException(detail="No sir, I don't like it.", status_code=400)
| litestar.exceptions.http_exceptions.HTTPException: 400: No sir, I don't like it. +------------------------------------ + Exception Group Traceback (most recent call last): | File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/middleware/exceptions/middleware.py", line 191, in __call__ | await self.app(scope, receive, send) | File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/routes/http.py", line 81, in handle | response = await self._get_response_for_request( | File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/routes/http.py", line 133, in _get_response_for_request | return await self._call_handler_function( | File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/routes/http.py", line 153, in _call_handler_function | response_data, cleanup_group = await self._get_response_data( | File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/routes/http.py", line 185, in _get_response_data | cleanup_group = await parameter_model.resolve_dependencies(request, kwargs) | File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/_kwargs/kwargs_model.py", line 393, in resolve_dependencies | async with create_task_group() as task_group: | File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 664, in __aexit__ | raise BaseExceptionGroup( | exceptiongroup.ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/_kwargs/dependencies.py", line 66, in resolve_dependency | value = await dependency.provide(**dependency_kwargs) | File "/tmp/litestarTest/.venv/lib/python3.10/site-packages/litestar/di.py", line 84, in __call__ | value = self.dependency.value(**kwargs) | File "/tmp/litestarTest/di_test_app.py", line 8, in get_dependency_child1 | raise HTTPException(detail="No sir, I don't like it.", status_code=400) | litestar.exceptions.http_exceptions.HTTPException: 400: No sir, I don't like it. +------------------------------------INFO: 127.0.0.1:54512 - "GET / HTTP/1.1" 500 Internal Server Error
Description
I have an application which uses heavily nested dependencies. Many of those dependencies have validation logic which throws HTTPExceptions so that users can update their requests and try again.
I am upgrading this from Starlite v1 and have hit an issue with how dependencies are handled when nesting occurs. It appears nested dependencies are processed concurrently within an
anyio.TaskGroup
instance. If any exception occurs in This instance of create_task_group, they all result in aGroupException
. Because of this, any HTTPExceptions thrown from inside the dependency logic gets yeeted into the void and the requester never sees it.URL to code causing the issue
No response
MCVE
Steps to reproduce
No response
Screenshots
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
Logs
Litestar Version
2.2.1
Platform
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh Litestar dashboard
The text was updated successfully, but these errors were encountered: