{
  "id": "python/starlette-testclient-lifespan-not-run",
  "signature": "httpx.ConnectError: All connection attempts failed (lifespan startup never executed)",
  "signature_zh": "httpx.ConnectError: 所有连接尝试均失败（lifespan 启动从未执行）",
  "regex": "httpx\\.ConnectError:\\ All\\ connection\\ attempts\\ failed\\ \\(lifespan\\ startup\\ never\\ executed\\)",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Using httpx.Client against app without running lifespan, so app.state resources (DB pool, clients) are None.",
  "root_cause_type": "generic",
  "root_cause_zh": "在未运行 lifespan 的情况下使用 httpx.Client 访问应用，导致 app.state 资源（数据库池、客户端）为 None。",
  "versions": [
    {
      "version": "0.100+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "0.110+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Misses teardown; leaks resources and diverges from prod.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Still no lifespan; same None state.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "from starlette.testclient import TestClient\nwith TestClient(app) as client:  # 'with' runs lifespan\n    r = client.get('/health')",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "Use httpx.ASGITransport with lifespan='on' via asgi-lifespan LifespanManager.",
      "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-04-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}