Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/semantic_kernel/connectors/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def _add_key(self, key: TKey, record: dict[str, Any]) -> dict[str, Any]:

@override
async def _inner_delete(self, keys: Sequence[str], **kwargs: Any) -> None:
await asyncio.gather(*[self.redis_database.json().delete(key, **kwargs) for key in keys])
await asyncio.gather(*[self.redis_database.json().delete(self._get_redis_key(key), **kwargs) for key in keys])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new helper call fails mypy: Argument 1 to "_get_redis_key" of "RedisCollection" has incompatible type "str"; expected "TKey" [arg-type] (https://github.com/microsoft/semantic-kernel/actions/runs/38998573858). _inner_delete still declares keys: Sequence[str], while _get_redis_key takes the collection's TKey. Please change this signature to Sequence[TKey], matching the hashset implementation and the collection key type, then rerun the type check.


@override
def _serialize_dicts_to_store_models(
Expand Down
18 changes: 18 additions & 0 deletions python/tests/unit/connectors/memory/test_redis_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,24 @@ async def test_delete(collection_hash, collection_json, type_):
await collection._inner_delete(["id1"])


@mark.parametrize("type_", ["hashset", "json"])
async def test_delete_applies_collection_name_prefix(
collection_with_prefix_hash, collection_with_prefix_json, mock_delete_hash, mock_delete_json, type_
):
"""Regression test for https://github.com/microsoft/semantic-kernel/issues/13904.

With prefix_collection_name_to_key_names=True, keys are stored as
"{collection_name}:{key}". The delete path must send the same
prefixed key, otherwise the record is never deleted.
"""
if type_ == "hashset":
await collection_with_prefix_hash._inner_delete(["id1"])
mock_delete_hash.assert_called_once_with("test:id1")
else:
await collection_with_prefix_json._inner_delete(["id1"])
mock_delete_json.assert_called_once_with("test:id1")


async def test_collection_exists(collection_hash, mock_collection_exists):
await collection_hash.collection_exists()

Expand Down
Loading