python
runtime_error
ai_generated
true
Exception in thread Thread-1 (run) ... AttributeError: 'NoneType' object has no attribute 'send'
ID: python/fastapi-background-task-exception-silent
80%Fix Rate
85%Confidence
0Evidence
2024-09-07First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 0.100.x | active | — | — | — |
| 0.110.x | active | — | — | — |
Root Cause
A background task raised an exception after the response was sent; Starlette logs it but the client never sees it.
generic中文
后台任务在响应发送后抛出异常;Starlette会记录但客户端看不到。
Workarounds
-
90% success
def task():\n try:\n work()\n except Exception:\n logger.exception('bg failed') -
92% success
@celery.task\ndef task(): ...\ntask.delay()
Dead Ends
Common approaches that don't work:
-
85% fail
Background tasks cannot return responses to the client.
-
70% fail
Still runs after response; exceptions remain invisible to client.