{
  "id": "python/starlette-missing-route-handler",
  "signature": "AssertionError: Route function must be async",
  "signature_zh": "断言错误：路由函数必须是异步的",
  "regex": "AssertionError:\\ Route\\ function\\ must\\ be\\ async",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A route handler in Starlette is defined as a synchronous function instead of async.",
  "root_cause_type": "generic",
  "root_cause_zh": "Starlette中的路由处理器被定义为同步函数而不是异步函数。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding @app.route without async",
      "why_fails": "Starlette requires async handlers; sync functions cause assertion errors.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Wrapping the function in a decorator that makes it async",
      "why_fails": "Complex and may not work correctly with Starlette's internals.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Define the route handler as async",
      "success_rate": 0.95,
      "how": "@app.route('/')\nasync def homepage(request):\n    return PlainTextResponse('Hello')",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a sync wrapper if absolutely necessary",
      "success_rate": 0.5,
      "how": "from starlette.responses import PlainTextResponse\n@app.route('/')\ndef sync_homepage(request):\n    return PlainTextResponse('Hello')",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-28",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}