fix: escape RediSearch-special characters in store delete queries#197
Open
jerry153fish wants to merge 1 commit into
Open
fix: escape RediSearch-special characters in store delete queries#197jerry153fish wants to merge 1 commit into
jerry153fish wants to merge 1 commit into
Conversation
…re delete queries The delete branch of _prepare_batch_PUT_queries / _aprepare_batch_PUT_queries interpolated the raw item key into the FT.SEARCH query, so delete()/adelete() raised 'SEARCH_SYNTAX Syntax error' for keys containing '-', '.', '#', etc. — put()/get() accept such keys, so filename-derived keys like 'my-doc.md#0' could be written but never deleted. Escape the key with _token_escaper, matching the already-escaped query in _batch_put_ops. Fixes redis-developer#196
limjoobin
approved these changes
Jul 10, 2026
limjoobin
left a comment
Contributor
There was a problem hiding this comment.
LGTM! Good catch, thanks!
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #196
Problem
store.delete()/store.adelete()raiseRedisSearchError: ... SEARCH_SYNTAX Syntax error ...for any key containing characters RediSearch treats as query syntax (-,.,#,@, …).put()/get()accept such keys, so filename-derived keys likemy-doc.md#0could be written but never deleted.Cause / fix
The delete branch of
_prepare_batch_PUT_queries(base.py) and_aprepare_batch_PUT_queries(aio.py) interpolated the raw key into the FT.SEARCH query:This PR escapes the key with
_token_escaper, matching the already-correct query in_batch_put_ops:Two one-line changes (async + sync stores).
Tests
tests/test_issue_196_store_delete_escaping.py— sync and async put → get → delete → get-is-None round-trips over five representative keys (my-doc.md#0,a-b,a.b,a#1,user@example.com). Both tests fail with the SEARCH_SYNTAX error before the fix and pass after; also verified manually against aredis:8container.