{
  "id": "python/fastapi-dependency-error-callable",
  "signature": "TypeError: 'Depends' object is not callable",
  "signature_zh": "类型错误：'Depends' 对象不可调用",
  "regex": "TypeError:\\ 'Depends'\\ object\\ is\\ not\\ callable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Using Depends incorrectly as a function instead of a dependency injection.",
  "root_cause_type": "generic",
  "root_cause_zh": "错误地将Depends用作函数而不是依赖注入。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Calling Depends() with parentheses inside a function parameter.",
      "why_fails": "Depends should be used without calling it; it's a class.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Importing Depends from the wrong module.",
      "why_fails": "Depends is from fastapi, not from fastapi.params.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use Depends as a parameter without calling it.",
      "success_rate": 0.95,
      "how": "from fastapi import Depends\nasync def read_items(db: Session = Depends(get_db)):",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using a callable dependency, define it as a function and pass it to Depends.",
      "success_rate": 0.9,
      "how": "def common_parameters(q: str = None):\n    return {'q': q}\n\n@app.get('/items')\nasync def read_items(commons: dict = Depends(common_parameters)):",
      "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-02-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}