Skip to content

Python: fix: apply collection-name prefix to keys in RedisJsonCollection._inner_delete#14060

Open
michaelxer wants to merge 2 commits into
microsoft:mainfrom
michaelxer:fix/redis-json-delete-prefix
Open

Python: fix: apply collection-name prefix to keys in RedisJsonCollection._inner_delete#14060
michaelxer wants to merge 2 commits into
microsoft:mainfrom
michaelxer:fix/redis-json-delete-prefix

Conversation

@michaelxer

Copy link
Copy Markdown

Motivation and Context

Fixes #13904

The method passes raw keys to without applying the collection-name prefix via . This causes deletes to fail when , because the prefixed keys used in upsert/get don't match the unprefixed keys passed to delete.

The sibling already correctly uses (line 581 of ).

Description

One-line fix in :

# Before (bug):
await asyncio.gather(*[self.redis_database.json().delete(key, **kwargs) for key in keys])

# After (fix):
await asyncio.gather(*[self.redis_database.json().delete(self._get_redis_key(key), **kwargs) for key in keys])

Test added in :

Added that verifies the collection-name prefix is applied to keys during delete for both hashset and JSON collection types.

Contribution Checklist

  • I have built and tested the code locally
  • Tests pass (28/28)

Copilot AI review requested due to automatic review settings June 6, 2026 22:53
@michaelxer michaelxer requested a review from a team as a code owner June 6, 2026 22:53
@moonbox3 moonbox3 added the python Pull requests for the Python Semantic Kernel label Jun 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes Redis JSON deletion to consistently apply the collection/key prefix and adds a unit test to validate delete behavior when a prefix is configured.

Changes:

  • Apply _get_redis_key(...) to Redis JSON .delete(...) calls in _inner_delete.
  • Add a unit test that verifies prefixed keys are passed to the underlying Redis delete API.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
python/semantic_kernel/connectors/redis.py Ensures JSON deletes use the prefixed Redis key via _get_redis_key.
python/tests/unit/connectors/memory/test_redis_store.py Adds coverage for delete behavior when a collection prefix is present.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +279 to +282
@mark.parametrize("type_", ["hashset", "json"])
async def test_delete_with_prefix(
collection_with_prefix_hash, collection_with_prefix_json, mock_delete_hash, mock_delete_json, type_
):
Comment on lines +292 to +296
# Verify the collection-name prefix was applied to the key
if type_ == "hashset":
mock_delete.assert_called_once_with("test:id1")
else:
mock_delete.assert_called_once_with("test:id1")
@github-actions github-actions Bot changed the title fix: apply collection-name prefix to keys in RedisJsonCollection._inner_delete Python: fix: apply collection-name prefix to keys in RedisJsonCollection._inner_delete Jun 6, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 89% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by michaelxer's agents

@michaelxer

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

…er_delete

The _inner_delete method in RedisJsonCollection was passing raw keys to
JSON.DEL without applying the collection-name prefix via
self._get_redis_key(). This caused deletes to fail when
prefix_collection_name_to_key_names=True, because the prefixed keys
used in upsert/get wouldn't match the unprefixed keys passed to delete.

The sibling RedisHashsetCollection._inner_delete already correctly uses
self._get_redis_key(key). This fix applies the same pattern to the JSON
collection.

Fixes microsoft#13904
Use request.getfixturevalue to resolve only the needed fixture per
parametrize case instead of injecting all four. Collapse the redundant
if/else assertion into a single assert.
@michaelxer michaelxer force-pushed the fix/redis-json-delete-prefix branch from adad746 to fee8451 Compare June 8, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Bug: RedisJsonCollection.delete() silently fails when prefix_collection_name_to_key_names is enabled

3 participants