# KeyError at /dashboard/ 'user_id'

- **ID:** `python/django-session-key-error`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to access a session key that does not exist.

## Version Compatibility

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

## Workarounds

1. **Use .get() method** (95% success)
   ```
   user_id = request.session.get('user_id')
   ```
2. **Check key existence** (90% success)
   ```
   if 'user_id' in request.session: ...
   ```

## Dead Ends

- **Using request.session['user_id'] without checking** — Raises KeyError if missing. (90% fail)
- **Assuming session always has the key** — Session may be empty or expired. (80% fail)
