{
  "id": "python/fastapi-dependency-cache-not-cleared",
  "signature": "AssertionError: Dependency cache is not cleared",
  "signature_zh": "断言错误：依赖缓存未清除。",
  "regex": "AssertionError:\\ Dependency\\ cache\\ is\\ not\\ cleared",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "FastAPI caches dependency results per request; improper use of global state or yield dependencies can cause stale data.",
  "root_cause_type": "generic",
  "root_cause_zh": "FastAPI 缓存每个请求的依赖结果；错误使用全局状态或 yield 依赖可能导致数据过期。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Global state persists across requests; cache not cleared between requests.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "FastAPI automatically caches; need to use yield for cleanup.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use yield dependencies properly: def get_db():\n    db = Session()\n    try:\n        yield db\n    finally:\n        db.close()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Set use_cache=False for dependencies that should not cache: Depends(get_db, use_cache=False)",
      "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.8,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-10-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}