-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Description
Discovered a very confusing footgun during a recent refactor with the peculiar syntax of RediSearch IndexDefinition and insufficient type checking.
Consider the following, sensible-looking code:
my_prefix = "MY:INDEXABLE:KEY:"
index_key = my_prefix + "index"
defn = IndexDefinition(prefix=my_prefix, index_type=IndexType.HASH)
redis_client.ft(index_key).create_index(my_fields, definition=defn)
What would we expect this to do?
Create an index of hashes prefixed by my_prefix ? No.
Error, because the arg prefix= expects an iterable? No..
Index every single hash prefixed by {"M", "Y", ":", "I", "N", "D", "E", "X", "A", "B", "L", "K"} ? It seems this is actually what happens.
Might I suggest IndexDefinition takes a keyword argument of prefixes= to indicate that it expects an iterable?
Or, in index_definition.py:
def _append_prefix(self, prefix):
"""Append PREFIX."""
if len(prefix) > 0:
self.args.append("PREFIX")
self.args.append(len(prefix))
for p in prefix:
self.args.append(p)
A quick raise RuntimeError if prefix is a string
Thanks for considering!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels