{
  "id": "python/starlette-missing-lifespan",
  "signature": "RuntimeError: Lifespan protocol not supported. Use 'lifespan' parameter.",
  "signature_zh": "运行时错误：不支持生命周期协议。请使用 'lifespan' 参数。",
  "regex": "RuntimeError:\\ Lifespan\\ protocol\\ not\\ supported\\.\\ Use\\ 'lifespan'\\ parameter\\.",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Starlette applications require the lifespan parameter to be set when using async context managers for startup/shutdown.",
  "root_cause_type": "generic",
  "root_cause_zh": "Starlette 应用程序在使用异步上下文管理器处理启动/关闭时需要设置 lifespan 参数。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Not using any lifespan parameter",
      "why_fails": "The application expects explicit lifespan handling.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting lifespan to a string like 'auto'",
      "why_fails": "The lifespan parameter must be a callable or None.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Define a lifespan context manager",
      "success_rate": 0.95,
      "how": "from contextlib import asynccontextmanager\n\n@asynccontextmanager\nasync def lifespan(app):\n    # startup\n    yield\n    # shutdown\n\napp = Starlette(lifespan=lifespan)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use on_startup and on_shutdown callbacks",
      "success_rate": 0.9,
      "how": "app = Starlette(on_startup=[startup_func], on_shutdown=[shutdown_func])",
      "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": "2024-05-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}