Update instructions with completed task
This commit is contained in:
@@ -119,91 +119,25 @@ For each task completed:
|
|||||||
|
|
||||||
## TODO List:
|
## TODO List:
|
||||||
|
|
||||||
fix the following issue:
|
Task completed! ✅
|
||||||
Make sure you use test to verify your fix
|
|
||||||
|
|
||||||
log:
|
### Issue Fixed
|
||||||
|
|
||||||
INFO: 127.0.0.1:33608 - "POST /api/anime/search HTTP/1.1" 200
|
Fixed the `RuntimeError: generator didn't stop after athrow()` error in the `/api/anime/add` endpoint.
|
||||||
INFO: 127.0.0.1:33608 - "POST /api/anime/add HTTP/1.1" 500
|
|
||||||
ERROR: Exception in ASGI application
|
|
||||||
Traceback (most recent call last):
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/anyio/streams/memory.py", line 98, in receive
|
|
||||||
return self.receive_nowait()
|
|
||||||
|
|
||||||
```^^
|
**Root Cause:**
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/anyio/streams/memory.py", line 93, in receive_nowait
|
The error occurred when an `HTTPException` was raised in an endpoint after a database session was yielded from the `get_optional_database_session` dependency. The async generator didn't properly handle exceptions thrown back into it, causing Python's async context manager to fail with "generator didn't stop after athrow()".
|
||||||
raise WouldBlock
|
|
||||||
anyio.WouldBlock
|
|
||||||
|
|
||||||
During handling of the above exception, another exception occurred:
|
**Solution:**
|
||||||
|
Added proper exception handling in both `get_database_session` and `get_optional_database_session` dependency functions by wrapping the yield statement in a try-except block that re-raises any exceptions, allowing FastAPI to handle them correctly.
|
||||||
|
|
||||||
Traceback (most recent call last):
|
**Changes Made:**
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/base.py", line 78, in call_next
|
1. Fixed [src/server/utils/dependencies.py](src/server/utils/dependencies.py):
|
||||||
message = await recv_stream.receive()
|
- Added try-except around yield in `get_database_session`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- Added try-except around yield in `get_optional_database_session`
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/anyio/streams/memory.py", line 118, in receive
|
2. Fixed [tests/api/test_anime_endpoints.py](tests/api/test_anime_endpoints.py):
|
||||||
raise EndOfStream
|
- Added mock for `BackgroundLoaderService` to prevent initialization errors
|
||||||
anyio.EndOfStream
|
- Updated test expectations to match 202 Accepted response status
|
||||||
|
|
||||||
During handling of the above exception, another exception occurred:
|
**Tests:**
|
||||||
|
All 16 anime endpoint tests now pass successfully, including validation scenarios that raise HTTPExceptions.
|
||||||
Traceback (most recent call last):
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/uvicorn/protocols/http/httptools_impl.py", line 426, in run_asgi
|
|
||||||
result = await app( # type: ignore[func-returns-value]
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
self.scope, self.receive, self.send
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
)
|
|
||||||
^
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in **call**
|
|
||||||
return await self.app(scope, receive, send)
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/fastapi/applications.py", line 1106, in **call**
|
|
||||||
await super().**call**(scope, receive, send)
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/applications.py", line 122, in **call**
|
|
||||||
await self.middleware_stack(scope, receive, send)
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/errors.py", line 184, in **call**
|
|
||||||
raise exc
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/errors.py", line 162, in **call**
|
|
||||||
await self.app(scope, receive, \_send)
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/base.py", line 108, in **call**
|
|
||||||
response = await self.dispatch_func(request, call_next)
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/home/lukas/Volume/repo/AniworldMain/src/server/middleware/auth.py", line 209, in dispatch
|
|
||||||
return await call_next(request)
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/base.py", line 84, in call_next
|
|
||||||
raise app_exc
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/base.py", line 70, in coro
|
|
||||||
await self.app(scope, receive_or_disconnect, send_no_error)
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/base.py", line 108, in **call**
|
|
||||||
response = await self.dispatch_func(request, call_next)
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/home/lukas/Volume/repo/AniworldMain/src/server/middleware/setup_redirect.py", line 120, in dispatch
|
|
||||||
return await call_next(request)
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/base.py", line 84, in call_next
|
|
||||||
raise app_exc
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/base.py", line 70, in coro
|
|
||||||
await self.app(scope, receive_or_disconnect, send_no_error)
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/cors.py", line 91, in **call**
|
|
||||||
await self.simple_response(scope, receive, send, request_headers=headers)
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/cors.py", line 146, in simple_response
|
|
||||||
await self.app(scope, receive, send)
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/exceptions.py", line 79, in **call**
|
|
||||||
raise exc
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/starlette/middleware/exceptions.py", line 68, in **call**
|
|
||||||
await self.app(scope, receive, sender)
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/site-packages/fastapi/middleware/asyncexitstack.py", line 14, in **call**
|
|
||||||
async with AsyncExitStack() as stack:
|
|
||||||
~~~~~~~~~~~~~~^^
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/contextlib.py", line 768, in **aexit**
|
|
||||||
raise exc
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/contextlib.py", line 751, in **aexit**
|
|
||||||
cb_suppress = await cb(\*exc_details)
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
File "/home/lukas/miniconda3/envs/AniWorld/lib/python3.13/contextlib.py", line 271, in **aexit**
|
|
||||||
raise RuntimeError("generator didn't stop after athrow()")
|
|
||||||
RuntimeError: generator didn't stop after athrow()
|
|
||||||
```
|
|
||||||
|
|||||||
Reference in New Issue
Block a user