{
  "id": "python/flask-cli-context-missing",
  "signature": "RuntimeError: Working outside of application context.\n\nThis typically means that you attempted to use functionality that needed\nthe current application.",
  "signature_zh": "RuntimeError: 在应用上下文之外工作。\n\n这通常意味着你尝试使用了需要当前应用的功能。",
  "regex": "RuntimeError:\\ Working\\ outside\\ of\\ application\\ context\\.\\\n\\\nThis\\ typically\\ means\\ that\\ you\\ attempted\\ to\\ use\\ functionality\\ that\\ needed\\\nthe\\ current\\ application\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A Flask CLI command or script accesses current_app/db without pushing an app context; @app.cli.command does not push one automatically in all cases.",
  "root_cause_type": "generic",
  "root_cause_zh": "Flask CLI 命令或脚本访问 current_app/db 时未推入应用上下文；@app.cli.command 并非在所有情况下自动推入。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Breaks application factory pattern and multi-app tests.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Circular imports and stale config.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.92,
      "how": "Use @with_appcontext decorator on CLI commands",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.93,
      "how": "with app.app_context(): db.create_all() in scripts",
      "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.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}