# RuntimeError: Working outside of application context.

- **ID:** `python/flask-working-outside-app-context`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 2.x | active | — | — |
| 3.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   from flask import current_app
with app.app_context():
    print(current_app.config['SECRET_KEY'])
   ```
2. **** (90% success)
   ```
   def worker():
    with app.app_context():
        # do work
        pass
   ```

## Dead Ends

- **** — test_request_context is meant for tests and doesn't push a proper app context for production use, leading to subtle bugs. (55% fail)
- **** — This config only affects exception propagation, not context availability. (90% fail)
