From 65bf78b567dbccb646b54a3479ae2f41fbe11edc Mon Sep 17 00:00:00 2001 From: yassin Date: Sun, 20 Sep 2026 09:16:50 +0000 Subject: [PATCH] fix(proxy): build Redis spend-log rows as tuples and pin the LTRIM window in the pipeline test Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/proxy/db/db_transaction_queue/redis_update_buffer.py | 4 ++-- tests/test_litellm/caching/test_redis_cache.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py b/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py index 9044bbb3d3b..534ba30a6d0 100644 --- a/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py +++ b/litellm/proxy/db/db_transaction_queue/redis_update_buffer.py @@ -554,7 +554,7 @@ class RedisUpdateBuffer: try: buffer_size: Final = await self.redis_cache.async_rpush_and_trim( key=REDIS_SPEND_LOGS_BUFFER_KEY, - values=[_encode_spend_log_row(row) for row in rows], + values=tuple(_encode_spend_log_row(row) for row in rows), max_len=max_rows, ) overflow: Final = buffer_size - max_rows @@ -582,7 +582,7 @@ class RedisUpdateBuffer: ) if popped is None: return () - encoded_rows: Final = popped if isinstance(popped, list) else [popped] + encoded_rows: Final = tuple(popped) if isinstance(popped, list) else (popped,) decoded_rows: Final = (_decode_spend_log_row(encoded) for encoded in encoded_rows) return tuple(row for row in decoded_rows if row is not None) diff --git a/tests/test_litellm/caching/test_redis_cache.py b/tests/test_litellm/caching/test_redis_cache.py index 44227b8ed33..5d72fe7213d 100644 --- a/tests/test_litellm/caching/test_redis_cache.py +++ b/tests/test_litellm/caching/test_redis_cache.py @@ -1549,4 +1549,4 @@ async def test_async_rpush_and_trim_runs_push_and_trim_in_one_transaction(monkey client.pipeline.assert_called_once_with(transaction=True) assert pushed_len == 4 assert rows == ["b", "c", "d"] - assert [op[:2] for op in pipe.queued] == [("rpush", "ns:buf"), ("ltrim", "ns:buf")] + assert pipe.queued == [("rpush", "ns:buf", "c", "d"), ("ltrim", "ns:buf", "-3", "-1")]