{
  "id": "python/fastapi-dependency-yield-cleanup",
  "signature": "RuntimeError: No response returned",
  "signature_zh": "运行时错误：未返回响应。",
  "regex": "RuntimeError:\\ No\\ response\\ returned",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "In FastAPI, a dependency with yield must be used as a generator; if you forget to yield or return, route fails.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 FastAPI 中，带有 yield 的依赖必须作为生成器使用；如果忘记 yield 或 return，路由会失败。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "FastAPI expects a generator for cleanup; return breaks it.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Dependency not invoked; no response generated.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "def get_db():\n    db = Session()\n    try:\n        yield db\n    finally:\n        db.close()\n\n@app.get('/')\ndef read(db = Depends(get_db)):\n    return {'db': db}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "If you need to return, use a regular function without yield.",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}