mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
fix(proxy): suppress BLE001 for cache-teardown catch, add coverage
The catch is deliberate (a cache backend failing to disconnect must not abort the remaining shutdown steps), so justify it instead of leaving the strict-lint budget over its ceiling. Adds a regression test for the try/except itself, closing the codecov patch-coverage gap.
This commit is contained in:
parent
daa2863e89
commit
f08b1c66a0
2 changed files with 26 additions and 1 deletions
|
|
@ -910,7 +910,7 @@ async def proxy_shutdown_event(worker_heartbeat: ProxyWorkerHeartbeat | None = N
|
|||
if litellm.cache is not None:
|
||||
try:
|
||||
await litellm.cache.disconnect()
|
||||
except Exception as e:
|
||||
except Exception as e: # noqa: BLE001 # cache teardown must not abort remaining shutdown steps
|
||||
verbose_proxy_logger.debug("Error disconnecting litellm.cache: %s", e)
|
||||
|
||||
await jwt_handler.close()
|
||||
|
|
|
|||
|
|
@ -205,6 +205,31 @@ async def test_proxy_shutdown_event_prisma_disconnect_raises_error(monkeypatch):
|
|||
await proxy_shutdown_event()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_proxy_shutdown_event_cache_disconnect_error_does_not_abort_shutdown(monkeypatch):
|
||||
"""A cache backend failing to disconnect must not skip the jwt_handler close
|
||||
that runs after it, unlike a prisma disconnect failure which does abort.
|
||||
"""
|
||||
monkeypatch.setattr(ps, "prisma_client", None, raising=False)
|
||||
|
||||
fake_jwt = MagicMock()
|
||||
fake_jwt.close = AsyncMock()
|
||||
monkeypatch.setattr(ps, "jwt_handler", fake_jwt, raising=False)
|
||||
monkeypatch.setattr(ps, "db_writer_client", None, raising=False)
|
||||
|
||||
import litellm
|
||||
|
||||
fake_cache = MagicMock()
|
||||
fake_cache.disconnect = AsyncMock(side_effect=RuntimeError("redis gone"))
|
||||
monkeypatch.setattr(litellm, "cache", fake_cache, raising=False)
|
||||
monkeypatch.setattr(litellm, "success_callback", [], raising=False)
|
||||
|
||||
await proxy_shutdown_event()
|
||||
|
||||
assert fake_cache.disconnect.await_count == 1
|
||||
assert fake_jwt.close.await_count == 1
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# _flush_spend_logs_queue_on_shutdown
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue