{
  "id": "python/fastapi-middleware-missing-await",
  "signature": "TypeError: 'coroutine' object is not callable",
  "signature_zh": "类型错误：协程对象不可调用",
  "regex": "TypeError:\\ 'coroutine'\\ object\\ is\\ not\\ callable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "FastAPI middleware function is defined as async but not awaited when calling the next middleware or request handler.",
  "root_cause_type": "generic",
  "root_cause_zh": "FastAPI中间件函数定义为异步，但在调用下一个中间件或请求处理器时未使用await。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding @app.middleware('http') without async def",
      "why_fails": "FastAPI expects an async function for middleware; synchronous functions cause different errors.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Removing async keyword from middleware function",
      "why_fails": "Middleware becomes synchronous but FastAPI still treats it as async, leading to runtime issues.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure middleware function uses await when calling call_next",
      "success_rate": 0.95,
      "how": "@app.middleware('http')\nasync def add_process_time_header(request: Request, call_next):\n    response = await call_next(request)\n    return response",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use synchronous middleware with proper decorator",
      "success_rate": 0.7,
      "how": "@app.middleware('http')\ndef sync_middleware(request: Request, call_next):\n    response = call_next(request)\n    return response",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}