{
  "id": "python/fastapi-background-task-not-awaited",
  "signature": "RuntimeWarning: coroutine 'send_email' was never awaited",
  "signature_zh": "RuntimeWarning: 协程 'send_email' 从未被 await。",
  "regex": "RuntimeWarning:\\ coroutine\\ 'send_email'\\ was\\ never\\ awaited",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Passing an async function to BackgroundTasks.add_task without awaiting; or calling an async function directly in a sync route without scheduling.",
  "root_cause_type": "generic",
  "root_cause_zh": "将异步函数传给 BackgroundTasks.add_task 而未 await；或在同步路由中直接调用异步函数而未调度。",
  "versions": [
    {
      "version": "0.100.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "0.110.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Task may be cancelled when request ends; not tracked by FastAPI.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Requires a running event loop and proper thread context; often raises RuntimeError.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "In async route: `background_tasks.add_task(send_email, to, body)` — FastAPI awaits it after response.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "For sync routes, use a sync function or `asyncio.run(send_email(...))` (careful with loops) or offload to Celery.",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-12-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}