This commit is contained in:
Ch Revanth reddy 2026-10-01 06:10:45 +05:30 • committed by GitHub
commit 100ca30e52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View file

@ -44,7 +44,7 @@ class AzureBlobCache(BaseCache):
print_verbose(f"LiteLLM SET Cache - Azure Blob. Key={key}. Value={value}")
serialized_value: Final = json.dumps(value)
try:
self.container_client.upload_blob(key, serialized_value)
self.container_client.upload_blob(key, serialized_value, overwrite=True)
except Exception as e:
# NON blocking - notify users Azure Blob is throwing an exception
print_verbose(f"LiteLLM set_cache() - Got exception from Azure Blob: {e}")

View file

@ -157,10 +157,36 @@ def test_blob_cache_sync_set_cache(mock_azure_dependencies):
# Verify the call was made correctly
cache.container_client.upload_blob.assert_called_once_with(
"sync_test_key", '{"sync_key": "sync_value", "number": 123}'
"sync_test_key", '{"sync_key": "sync_value", "number": 123}', overwrite=True
)
def test_blob_cache_sync_set_cache_replaces_an_existing_key(mock_azure_dependencies):
"""Re-caching a key must replace the blob, as the async path already does.
`ContainerClient.upload_blob` defaults to `overwrite=False` and raises
`ResourceExistsError` for a key that is already present. `set_cache`
swallows that, so without `overwrite=True` the entry silently never updates.
"""
from azure.core.exceptions import ResourceExistsError
cache = AzureBlobCache("https://my-test-host", "test-container")
existing_keys = {"sync_test_key"}
def upload_blob(name, data, **kwargs):
if name in existing_keys and not kwargs.get("overwrite"):
raise ResourceExistsError("The specified blob already exists.")
existing_keys.add(name)
return MagicMock()
cache.container_client.upload_blob.side_effect = upload_blob
cache.set_cache("sync_test_key", {"v": 2})
assert cache.container_client.upload_blob.call_args.kwargs.get("overwrite") is True
def test_blob_cache_sync_get_cache_not_found(mock_azure_dependencies):
"""Test sync get_cache method when blob is not found"""