Python: fix(redis): wrap IndexDefinition prefix in list; use _get_redis_key in JSON delete
Summary
Two bugs in python/semantic_kernel/connectors/redis.py:
Bug 1 — IndexDefinition prefix iterates character-by-character (fixes #13894)
ensure_collection_exists passed a bare str as the prefix argument:
# before
index_definition = IndexDefinition(
prefix=f"{self.collection_name}:", index_type=...
)
redis-py's IndexDefinition accepts an iterable of prefixes. When passed a plain string it iterates character by character, generating a PREFIX N c o l l e c t i o n ... clause instead of PREFIX 1 collection_name:. This causes the index to match nothing (or incorrectly).
# after
index_definition = IndexDefinition(
prefix=[f"{self.collection_name}:"], index_type=...
)
Bug 2 — RedisJsonCollection._inner_delete silently no-ops (fixes #13904)
_inner_delete passed the raw caller key to json().delete():
# before
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])
But _single_upsert stores keys as {collection_name}:{key} (via _get_redis_key). The delete always targeted a non-existent key and returned 0 without raising. RedisHashsetCollection._inner_delete already uses _get_redis_key correctly.
# after
async def _inner_delete(self, keys: Sequence[str], **kwargs: Any) -> None:
await asyncio.gather(*[self.redis_database.json().delete(self._get_redis_key(key), **kwargs) for key in keys])
Testing
Both fixes are straightforward and can be verified with a live Redis instance by:
- Creating a
RedisJsonCollection, upserting a record, then deleting it and confirming it's gone. - Checking
FT.INFO <collection_name>to confirm thePREFIXclause is1 <collection_name>:afterensure_collection_exists.