{
  "id": "python/starlette-missing-app-instance",
  "signature": "RuntimeError: The ASGI application instance is not available.",
  "signature_zh": "运行时错误: ASGI应用程序实例不可用。",
  "regex": "RuntimeError:\\ The\\ ASGI\\ application\\ instance\\ is\\ not\\ available\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "尝试在Starlette应用之外访问app实例，例如在导入时或测试中未正确设置。",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试在Starlette应用之外访问app实例，例如在导入时或测试中未正确设置。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "在模块级别直接访问app对象",
      "why_fails": "app可能尚未创建或已被回收。",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "使用全局变量存储app引用",
      "why_fails": "多线程环境下可能导致竞态条件。",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "在应用上下文中访问app，例如通过request.app",
      "success_rate": 0.95,
      "how": "from starlette.requests import Request; async def my_endpoint(request: Request): app = request.app; return JSONResponse({'app': str(app)})",
      "condition": "",
      "sources": []
    },
    {
      "action": "在测试中使用TestClient时确保app已创建",
      "success_rate": 0.9,
      "how": "from starlette.testclient import TestClient; from main import app; client = TestClient(app); response = client.get('/')",
      "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-02-28",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}