{
  "id": "python/flask-working-outside-app-context",
  "signature": "RuntimeError: Working outside of application context.",
  "signature_zh": "RuntimeError：在应用程序上下文之外工作。",
  "regex": "RuntimeError:\\ Working\\ outside\\ of\\ application\\ context\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Accessing Flask's current_app or other context-local proxies without an active application context, common in background threads, CLI scripts, or Celery tasks.",
  "root_cause_type": "generic",
  "root_cause_zh": "在没有活动应用程序上下文的情况下访问 Flask 的 current_app 或其他上下文局部代理，常见于后台线程、CLI 脚本或 Celery 任务中。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "test_request_context is meant for tests and doesn't push a proper app context for production use, leading to subtle bugs.",
      "fail_rate": 0.55,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This config only affects exception propagation, not context availability.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "from flask import current_app\nwith app.app_context():\n    print(current_app.config['SECRET_KEY'])",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def worker():\n    with app.app_context():\n        # do work\n        pass",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}