Skip to content

Python: fix(redis): pass collection prefix as a list#13903

Open
MukundaKatta wants to merge 1 commit intomicrosoft:mainfrom
MukundaKatta:codex/semantic-kernel-redis-prefix
Open

Python: fix(redis): pass collection prefix as a list#13903
MukundaKatta wants to merge 1 commit intomicrosoft:mainfrom
MukundaKatta:codex/semantic-kernel-redis-prefix

Conversation

@MukundaKatta
Copy link
Copy Markdown

Summary

  • pass Redis IndexDefinition.prefix as a single-item list instead of a plain string
  • update the manual test fixture to match the correct redis-py API shape
  • add a regression test that asserts the connector builds the index definition with exactly one collection prefix

Closes #13894

Verification

  • ran git diff --check
  • added a focused unit test around ensure_collection_exists() prefix construction

Notes

  • I did not run the Python test suite locally because the required Redis/Python test dependencies were not installed in this environment.

@MukundaKatta MukundaKatta requested a review from a team as a code owner April 21, 2026 15:27
@moonbox3 moonbox3 added the python Pull requests for the Python Semantic Kernel label Apr 21, 2026
@github-actions github-actions Bot changed the title fix(redis): pass collection prefix as a list Python: fix(redis): pass collection prefix as a list Apr 21, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

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: 95%

✗ Correctness

The production code fix (wrapping the prefix argument in a list) is correct — IndexDefinition._append_prefix calls len(prefix) and iterates over it, so passing a bare string like "test:" would produce PREFIX 5 t e s t : instead of the intended PREFIX 1 test:. However, the new test test_create_index_uses_single_collection_prefix has a bug: it parametrizes expected_index_type as "hash"/"json" strings, then passes them to IndexType(expected_index_type). Since IndexType is an Enum with integer values (HASH = 1, JSON = 2), calling IndexType("hash") raises ValueError: 'hash' is not a valid IndexType. The test will fail at assertion time, not because the code is wrong, but because the expected value cannot be constructed.

✓ Security Reliability

This is a correctness bug fix for the Redis connector. The IndexDefinition constructor's prefix parameter is iterable, and passing a bare string like "test:" causes redis-py to iterate over each character as a separate prefix (e.g., "t", "e", "s", "t", ":") instead of treating the whole string as one prefix. Wrapping it in a list ["test:"] ensures the prefix is correctly interpreted as a single entry. The new test properly validates this behavior by patching IndexDefinition and asserting it receives the list form. No security or reliability issues found.

✓ Test Coverage

The diff changes the prefix argument to IndexDefinition from a bare string to a single-element list, matching the redis-py API expectation. The existing test_create_index_manual test is updated to reflect the new list format, and a new parametrized test test_create_index_uses_single_collection_prefix is added to verify both hash and JSON collection types pass prefix=["test:"] to IndexDefinition. The new test properly patches IndexDefinition at the correct import path, asserts call arguments, and verifies the returned definition object is forwarded to create_index. Test coverage for this change is thorough.

✗ Design Approach

The core fix — changing prefix=f"{self.collection_name}:" (a string) to prefix=[f"{self.collection_name}:"] (a list) — is correct and necessary. IndexDefinition._append_prefix iterates with for p in prefix, so a bare string would iterate individual characters, producing 5 (or more) nonsense prefix entries instead of one. The accompanying test update to test_create_index_manual is also correct. However, the new parametrized test test_create_index_uses_single_collection_prefix contains a bug: it passes string values "hash" and "json" to IndexType(expected_index_type), but IndexType is a standard Enum with integer values (HASH=1, JSON=2). IndexType("hash") will raise ValueError: 'hash' is not a valid IndexType at test execution time, meaning the new test always fails and provides no coverage.


Automated review by MukundaKatta's agents

Comment on lines +310 to +315

@mark.parametrize(
("fixture_name", "expected_index_type"),
[
("collection_hash", "hash"),
("collection_json", "json"),
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.

Bug: IndexType("hash") and IndexType("json") will raise ValueError because IndexType is an Enum with integer values (HASH = 1, JSON = 2), not string values. The parametrize should use the actual IndexType enum members directly.

Suggested change
@mark.parametrize(
("fixture_name", "expected_index_type"),
[
("collection_hash", "hash"),
("collection_json", "json"),
@mark.parametrize(
("fixture_name", "expected_index_type"),
[
("collection_hash", IndexType.HASH),
("collection_json", IndexType.JSON),
],
)

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: Redis connector sends malformed FT.CREATE PREFIX (one prefix per character of collection name)

2 participants