# RuntimeError: Working outside of request context.

- **ID:** `python/flask-test-client-context-missing`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Using flask.request or session outside of a request context, e.g., in test setup or background tasks.

## Version Compatibility

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

## Workarounds

1. **** (95% success)
   ```
   with app.test_request_context('/'):
    # use request
   ```
2. **** (80% success)
   ```
   For background tasks, pass request data explicitly instead of using context.
   ```

## Dead Ends

- **** — Must use with app.test_request_context(): to push context. (85% fail)
- **** — Request context is tied to thread; async tasks may not have it. (90% fail)
