# AssertionError: Dependency cache is not cleared

- **ID:** `python/fastapi-dependency-cache-not-cleared`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

FastAPI caches dependency results per request; improper use of global state or yield dependencies can cause stale data.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   Use yield dependencies properly: def get_db():
    db = Session()
    try:
        yield db
    finally:
        db.close()
   ```
2. **** (85% success)
   ```
   Set use_cache=False for dependencies that should not cache: Depends(get_db, use_cache=False)
   ```

## Dead Ends

- **** — Global state persists across requests; cache not cleared between requests. (80% fail)
- **** — FastAPI automatically caches; need to use yield for cleanup. (60% fail)
