{
  "id": "python/fastapi-runtimeerror-dependency-cache-key-must-be-hashable",
  "signature": "RuntimeError: Dependency cache key must be hashable",
  "signature_zh": "RuntimeError: 依赖缓存键必须是可哈希的",
  "regex": "RuntimeError:\\ Dependency\\ cache\\ key\\ must\\ be\\ hashable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Using a mutable object (like a list or dict) as a dependency parameter that FastAPI tries to cache.",
  "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": "Using a list as a default value for a dependency.",
      "why_fails": "Lists are mutable and unhashable, causing caching issues.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using a dict as a query parameter.",
      "why_fails": "Query parameters must be hashable; dicts are not.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use immutable types like tuple instead of list.",
      "success_rate": 0.9,
      "how": "from typing import Tuple\nasync def dependency(items: Tuple[int, ...] = (1, 2, 3)):\n    return items",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use Pydantic models for complex parameters.",
      "success_rate": 0.95,
      "how": "from pydantic import BaseModel\nclass FilterParams(BaseModel):\n    tags: list[str] = []\n\nasync def dependency(params: FilterParams):\n    return params",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}