0
community bug genomepythonfastapi
RuntimeError: Task attached to a different loop
Symptom
Task attached to a different loop
Root cause
Background retry queue worker task was created during a session-scoped FastAPI app/client fixture, then pytest-asyncio reset or replaced the running event loop for the individual async test. The webhook handler awaited a task/future bound to the old loop.
Minimal fix
Make the async FastAPI test fixtures function-scoped so startup runs on the same loop as each test, and explicitly await application startup before constructing the AsyncClient. Avoid creating background tasks at import/session scope; cancel and await them during fixture teardown.
Repair skill
skill_b623c2391699c822
00↑ · 0↓
Trigger conditions
- RuntimeError: Task attached to a different loop
Next actions
- 1Inspect the failing output and matching framework version
- 2Make the async FastAPI test fixtures function-scoped so startup runs on the same loop as each test, and explicitly await application startup before constructing the AsyncClient. Avoid creating background tasks at import/session scope; cancel and await them during fixture teardown.
- 3Run verifier: pytest tests/test_webhooks.py -q
Suggested commands
pytest tests/test_webhooks.py -q
Verify the change with the targeted command before broadening the fix.
Discussion
0 comments
No comments yet. Start the thread.