{
  "id": "python/fastapi-runtimeerror-starlette-context-already-exists",
  "signature": "RuntimeError: ContextVar 'context' already exists",
  "signature_zh": "运行时错误：ContextVar 'context'已经存在",
  "regex": "RuntimeError:\\ ContextVar\\ 'context'\\ already\\ exists",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Duplicate declaration of a ContextVar in the same scope, often due to middleware or dependency injection conflicts.",
  "root_cause_type": "generic",
  "root_cause_zh": "在同一作用域中重复声明了ContextVar，通常是由于中间件或依赖注入冲突。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Ignoring the error and retrying",
      "why_fails": "ContextVar conflict persists until code is fixed.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using different variable names without understanding",
      "why_fails": "Root cause is duplicate declaration, not name.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Remove duplicate ContextVar declaration",
      "success_rate": 0.9,
      "how": "Ensure only one declaration: from contextvars import ContextVar\ncontext = ContextVar('context', default=None)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a single ContextVar across modules",
      "success_rate": 0.85,
      "how": "Create a shared module for ContextVar and import it.",
      "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.81,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-03-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}