{
  "id": "python/task-exception-never-retrieved",
  "signature": "Task exception was never retrieved\nfuture: <Task finished name='Task-5' coro=<worker() done, defined at app.py:42> exception=ValueError('bad payload')>",
  "signature_zh": "Task exception was never retrieved\nfuture: <Task finished name='Task-5' coro=<worker() done, defined at app.py:42> exception=ValueError('bad payload')>",
  "regex": "Task\\ exception\\ was\\ never\\ retrieved\\\nfuture:\\ <Task\\ finished\\ name='Task\\-5'\\ coro=<worker\\(\\)\\ done,\\ defined\\ at\\ app\\.py:42>\\ exception=ValueError\\('bad\\ payload'\\)>",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A task created with asyncio.create_task() raised an exception, but no one awaited the task or attached a done callback, so the exception is discarded.",
  "root_cause_type": "generic",
  "root_cause_zh": "通过 asyncio.create_task() 创建的任务抛出异常，但没有人 await 该任务或附加完成回调，因此异常被丢弃。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Only adds more logging; the underlying exception is still lost.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Hides real bugs and still leaves the task result unretrieved.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Does not attach a handler to the task's exception.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Attach a done callback that logs exceptions:\n\ndef _log(task):\n    if (exc := task.exception()):\n        logger.exception('task failed', exc_info=exc)\n\ntask = asyncio.create_task(worker())\ntask.add_done_callback(_log)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Keep strong references and await tasks in a TaskGroup (3.11+):\n\nasync with asyncio.TaskGroup() as tg:\n    tg.create_task(worker())",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "For fire-and-forget, store tasks in a module-level set and remove in the callback to prevent GC.",
      "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.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}