fix(redis_cache): apply namespace prefix in delete_cache and async_delete_cache - #26790
fix(redis_cache): apply namespace prefix in delete_cache and async_delete_cache#26790elluvium wants to merge 1 commit into
Conversation
When a Redis namespace is configured, SET and GET correctly prefix the key via check_and_fix_namespace, but DELETE did not — causing the PodLockManager to always target a non-existent key and never explicitly release locks (they would expire by TTL instead, with a warning on every cycle). Adds check_and_fix_namespace to both async_delete_cache and delete_cache, and covers both paths with a parametrized unit test (namespace=None / "myns").
Greptile SummaryThis PR fixes a namespace prefix bug in Confidence Score: 5/5Safe to merge — minimal, targeted fix with proper test coverage and no regressions. The change is a one-liner applied to two methods, consistent with the established pattern in all other cache operations. Tests cover both the No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/caching/redis_cache.py | Adds check_and_fix_namespace call to async_delete_cache and delete_cache, matching the existing pattern used in every other cache method; also adds type annotation to delete_cache. |
| tests/test_litellm/caching/test_redis_cache.py | Adds test_delete_cache_applies_namespace parametrized over None/"myns" covering both async and sync delete paths with mocks; also removes unused fastapi.testclient.TestClient import. |
Reviews (1): Last reviewed commit: "fix(redis_cache): apply namespace in del..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
🤖 litellm-agent: Auto-merge skipped — the staging branch Please rebase your branch onto |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Summary
async_delete_cacheanddelete_cacheinlitellm/caching/redis_cache.pywere not callingcheck_and_fix_namespace()before issuing the RedisDELcommandnamespaceis configured,SETandGETcorrectly prefix the key (e.g.litellm.caching.caching:cronjob_lock:db_spend_update_job), butDELtargeted the raw key — which does not exist — so it always returned 0PodLockManagerto never explicitly release locks; every lock expired by TTL instead, producing afailed to release Redis lockwarning on every batch-write cycle for every podChanges
litellm/caching/redis_cache.py: addkey = self.check_and_fix_namespace(key=key)to bothasync_delete_cacheanddelete_cache, matching the pattern used in every other cache methodtests/test_litellm/caching/test_redis_cache.py: addtest_delete_cache_applies_namespace— parametrized overnamespace=Noneandnamespace="myns"— asserting the correct key is passed toredis_client.deletein both the async and sync pathsTest plan
uv run pytest tests/test_litellm/caching/test_redis_cache.py -v— all 26 tests passuv run ruff check litellm/caching/redis_cache.py tests/test_litellm/caching/test_redis_cache.py— cleanuv run mypy litellm/caching/redis_cache.py --ignore-missing-imports— no issues