# RuntimeError: Working outside of application context.

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

## Root Cause

Accessing Flask's current_app, g, or url_for outside of an application context, often when using background threads or standalone scripts.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   with app.app_context():
    # code that needs current_app
   ```
2. **** (90% success)
   ```
   from flask import current_app
app = create_app()
with app.app_context():
    # use current_app
   ```

## Dead Ends

- **** — Threads don't inherit the context automatically; app objects require an explicit context. (90% fail)
- **** — test_request_context returns a context manager; not entering it leaves the context inactive. (85% fail)
