{
  "id": "python/flask-app-context-runtime-error",
  "signature": "RuntimeError: Working outside of application context.",
  "signature_zh": "运行时错误：在应用上下文之外工作。",
  "regex": "RuntimeError:\\ Working\\ outside\\ of\\ application\\ context\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to access Flask's application context (e.g., current_app, g, url_for) outside of a request or app context, typically in a background thread or standalone script.",
  "root_cause_type": "generic",
  "root_cause_zh": "在请求或应用上下文之外尝试访问Flask的应用上下文（如current_app、g、url_for），通常发生在后台线程或独立脚本中。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Using app.test_request_context() without entering it works only within a with block, but calling it outside causes the same error.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Setting app.app_context().push() manually can leak context and cause issues in multi-threaded environments.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "with app.app_context():\\n    # access current_app or url_for\\n    pass",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Within a Flask request handler, the context is automatically available; move the code inside a view function.",
      "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-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}