{
  "id": "python/starlette-background-task-error",
  "signature": "RuntimeError: Background task failed: 'NoneType' object has no attribute 'send'",
  "signature_zh": "运行时错误：后台任务失败：'NoneType'对象没有'send'属性",
  "regex": "RuntimeError:\\ Background\\ task\\ failed:\\ 'NoneType'\\ object\\ has\\ no\\ attribute\\ 'send'",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A background task function is not defined as async or is called incorrectly, causing the ASGI server to fail when trying to run it.",
  "root_cause_type": "generic",
  "root_cause_zh": "后台任务函数未定义为async或调用不正确，导致ASGI服务器尝试运行时失败。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Calling the background task function directly instead of passing it to BackgroundTask causes immediate execution.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Making the task synchronous works in some cases but blocks the event loop.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Define the task as async: async def send_email(email: str):\\n    # ...\\nthen use BackgroundTask(send_email, email)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use Starlette's BackgroundTasks: background_tasks.add_task(send_email, email)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-25",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}