# RuntimeError: Working outside of application context.

- **ID:** `python/flask-runtimeerror-application-context-not-available`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Code tries to access application-level context (e.g., current_app, g) outside of an application context, such as in a background thread or before first request.

## Version Compatibility

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

## Workarounds

1. **Push application context manually** (90% success)
   ```
   with app.app_context():
    # access current_app here
    pass
   ```
2. **Use Flask's before_first_request decorator** (85% success)
   ```
   @app.before_first_request
def setup():
    # setup code here
    pass
   ```

## Dead Ends

- **Using current_app in a module-level variable** — Module-level code runs before app context exists. (80% fail)
- **Assuming g is always available** — g is request-specific and only available within request context. (70% fail)
