Skip to content

Commit cd08209

Browse files
Copilotabrookins
andcommitted
Return correct DeleteQueryResponse shape for empty attributes
- Changed delete_by_attributes() to return {"deleted_entries_count": 0} instead of {} - Changed adelete_by_attributes() to return {"deleted_entries_count": 0} instead of {} - Updated tests to verify correct response shape - This matches the DeleteQueryResponse structure from LangCache SDK Co-authored-by: abrookins <[email protected]>
1 parent 5d02f58 commit cd08209

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

redisvl/extensions/cache/llm/langcache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ def delete_by_attributes(self, attributes: Dict[str, Any]) -> Dict[str, Any]:
588588
Dict[str, Any]: Result of the deletion operation.
589589
"""
590590
if not attributes:
591-
# No attributes provided, return empty result without calling API
592-
return {}
591+
# No attributes provided, return result with zero deletions
592+
return {"deleted_entries_count": 0}
593593
result = self._client.delete_query(attributes=attributes)
594594
# Convert DeleteQueryResponse to dict
595595
return result.model_dump() if hasattr(result, "model_dump") else {}
@@ -605,8 +605,8 @@ async def adelete_by_attributes(self, attributes: Dict[str, Any]) -> Dict[str, A
605605
Dict[str, Any]: Result of the deletion operation.
606606
"""
607607
if not attributes:
608-
# No attributes provided, return empty result without calling API
609-
return {}
608+
# No attributes provided, return result with zero deletions
609+
return {"deleted_entries_count": 0}
610610
result = await self._client.delete_query_async(attributes=attributes)
611611
# Convert DeleteQueryResponse to dict
612612
return result.model_dump() if hasattr(result, "model_dump") else {}

tests/unit/test_langcache_semantic_cache.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def test_delete_by_attributes_with_valid_attributes(self, mock_langcache_client)
458458
def test_delete_by_attributes_with_empty_attributes_returns_empty(
459459
self, mock_langcache_client
460460
):
461-
"""Test that delete_by_attributes returns empty dict with empty attributes."""
461+
"""Test that delete_by_attributes returns correct shape with empty attributes."""
462462
_, mock_client = mock_langcache_client
463463

464464
cache = LangCacheSemanticCache(
@@ -470,8 +470,8 @@ def test_delete_by_attributes_with_empty_attributes_returns_empty(
470470

471471
result = cache.delete_by_attributes({})
472472

473-
# Should return empty dict without calling delete_query
474-
assert result == {}
473+
# Should return dict with correct shape without calling delete_query
474+
assert result == {"deleted_entries_count": 0}
475475
mock_client.delete_query.assert_not_called()
476476

477477
@pytest.mark.asyncio
@@ -503,7 +503,7 @@ async def test_adelete_by_attributes_with_valid_attributes(
503503
async def test_adelete_by_attributes_with_empty_attributes_returns_empty(
504504
self, mock_langcache_client
505505
):
506-
"""Test that async delete_by_attributes returns empty dict with empty attributes."""
506+
"""Test that async delete_by_attributes returns correct shape with empty attributes."""
507507
_, mock_client = mock_langcache_client
508508

509509
cache = LangCacheSemanticCache(
@@ -515,8 +515,8 @@ async def test_adelete_by_attributes_with_empty_attributes_returns_empty(
515515

516516
result = await cache.adelete_by_attributes({})
517517

518-
# Should return empty dict without calling delete_query_async
519-
assert result == {}
518+
# Should return dict with correct shape without calling delete_query_async
519+
assert result == {"deleted_entries_count": 0}
520520
mock_client.delete_query_async.assert_not_called()
521521

522522
def test_update_not_supported(self, mock_langcache_client):

0 commit comments

Comments
 (0)