{
  "id": "python/fastapi-runtimeerror-dependency-cache-key-error",
  "signature": "RuntimeError: Dependency cache key error",
  "signature_zh": "运行时错误：依赖缓存键错误",
  "regex": "RuntimeError:\\ Dependency\\ cache\\ key\\ error",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "FastAPI's dependency injection cache has a conflict, often due to using mutable default arguments in dependency functions.",
  "root_cause_type": "generic",
  "root_cause_zh": "FastAPI的依赖注入缓存存在冲突，通常是由于在依赖函数中使用了可变默认参数。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Ignoring mutable defaults in dependencies",
      "why_fails": "Mutable defaults are shared across requests, causing cache issues.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using global variables in dependencies",
      "why_fails": "Global state can cause cache key collisions.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use immutable defaults or None",
      "success_rate": 0.9,
      "how": "def dependency(items: list = None):\n    if items is None:\n        items = []",
      "condition": "",
      "sources": []
    },
    {
      "action": "Clear dependency cache manually",
      "success_rate": 0.5,
      "how": "from fastapi import Depends\n# Not recommended; better to fix dependency function",
      "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.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-08-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}