-
Notifications
You must be signed in to change notification settings - Fork 93
fix(mcp): escape text filter values and reject an empty projection #667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7a25665
fix(mcp): escape text filter values and reject an empty projection
vishal-bala 8e7a87f
fix(mcp): reject a text_field_name that points at a vector field
vishal-bala e2b310b
fix(mcp): stop over-escaping `like` pattern metacharacters
vishal-bala 1a1c078
test(mcp): pin the one case where a falsy projection reaches a query
vishal-bala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,43 @@ | ||
| import pytest | ||
|
|
||
| from redisvl.schema import IndexSchema | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session", autouse=True) | ||
| def redis_container(): | ||
| # Shadow the repo-wide autouse Redis container fixture so MCP unit tests stay | ||
| # pure-unit and do not require Docker; Redis coverage lives in integration tests. | ||
| yield None | ||
|
|
||
|
|
||
| def _schema() -> IndexSchema: | ||
| """The one index shape the filter, search, and profile unit tests all build against. | ||
|
|
||
| A plain function rather than a fixture: it is a stateless data builder that | ||
| module-level parametrization and helper functions both need to call, and the | ||
| convention in these files is per-module fakes rather than shared fixtures. | ||
| """ | ||
| return IndexSchema.from_dict( | ||
| { | ||
| "index": { | ||
| "name": "docs-index", | ||
| "prefix": "doc", | ||
| "storage_type": "hash", | ||
| }, | ||
| "fields": [ | ||
| {"name": "content", "type": "text"}, | ||
| {"name": "category", "type": "tag"}, | ||
| {"name": "rating", "type": "numeric"}, | ||
| { | ||
| "name": "embedding", | ||
| "type": "vector", | ||
| "attrs": { | ||
| "algorithm": "flat", | ||
| "dims": 3, | ||
| "distance_metric": "cosine", | ||
| "datatype": "float32", | ||
| }, | ||
| }, | ||
| ], | ||
| } | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are sure that this return_fields won't get caught as a falsy value that could be interpreted 2 different ways (empty vs omitted)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good instinct — the answer splits in two, and the second half found a gap worth pinning. Added a test in 1a1c078.
At this boundary: no, they can't be confused. The branch is
if return_fields is None, not a truthiness check, so[]falls through to theelseand hits the explicit rejection. Verified both ways:And it's guarded, not incidental: weakening that line to
if not return_fieldsmakestest_search_records_rejects_an_empty_return_fields_listfail.One layer down, though, you're pointing at something real. The default projection is every non-vector field, so an index whose only field is the vector resolves it to
[]— and RedisVL does read a falsyreturn_fieldsas "no projection" and omits RETURN entirely:That path is safe today only because
VectorQueryaddsvector_distanceto its own return fields, so a RETURN clause gets emitted anyway. That dependency was implicit — nothing would have caught it changing — so there's now a test asserting the default projection really is empty there, that the built query still carries RETURN, and that what comes back is the score rather than the embedding.Fulltext and hybrid can't reach that state at all as of 8e7a87f, which requires
text_field_nameto be a non-vector field and so always puts it in the projection.🤖 Addressed by Claude Code