{
  "id": "python/fastapi-dependency-cache-error",
  "signature": "RuntimeError: Dependency 'get_db' returned a value that is not a valid dependency",
  "signature_zh": "运行时错误：依赖项 'get_db' 返回的值不是有效的依赖项",
  "regex": "RuntimeError:\\ Dependency\\ 'get_db'\\ returned\\ a\\ value\\ that\\ is\\ not\\ a\\ valid\\ dependency",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "FastAPI 依赖注入函数返回了非可调用的对象",
  "root_cause_type": "generic",
  "root_cause_zh": "FastAPI 依赖注入函数返回了非可调用的对象",
  "versions": [
    {
      "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "在依赖函数中返回 None",
      "why_fails": "None 不是有效依赖",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "使用类作为依赖但不实例化",
      "why_fails": "FastAPI 需要可调用对象",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "确保依赖函数返回可调用对象或正确类型",
      "success_rate": 0.95,
      "how": "def get_db():\n    return SessionLocal()  # 返回实例而非类",
      "condition": "",
      "sources": []
    },
    {
      "action": "使用类作为依赖并正确配置",
      "success_rate": 0.9,
      "how": "class CommonQueryParams:\n    def __init__(self, q: str = None):\n        self.q = q\n@app.get('/items')\ndef get_items(params: CommonQueryParams = Depends()):\n    ...",
      "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-09-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}