redis / redis-py

Redis Python client
MIT License
12.41k stars 2.48k forks source link

redisearch ft().profile encounter error #3302

Open xRay2016 opened 1 week ago

xRay2016 commented 1 week ago

Version: 5.0.4

Platform: python 3.7.16 on mac

Description: When I use ft.profile() command, it seems that the result is not parsed correctly. The error log is as follow:

client = Redis<ConnectionPool<Connection<host=redis-sy018bfbwp5w97ckz.redis.volces.com,port=6379,db=0>>>

    @pytest.mark.redismod
    @pytest.mark.onlynoncluster
    def test_profile_limited(client):
        client.ft().create_index((TextField("t"),))
        client.ft().client.hset("1", "t", "hello")
        client.ft().client.hset("2", "t", "hell")
        client.ft().client.hset("3", "t", "help")
        client.ft().client.hset("4", "t", "helowa")

        q = Query("%hell% hel*")
        if is_resp2_connection(client):
>           res, det = client.ft().profile(q, limited=True)

tests/test_search.py:1952: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/Caskroom/miniconda/base/envs/test/lib/python3.7/site-packages/redis/commands/search/commands.py:616: in profile
    PROFILE_CMD, res, query=query, duration=(time.time() - st) * 1000.0
/usr/local/Caskroom/miniconda/base/envs/test/lib/python3.7/site-packages/redis/commands/search/commands.py:70: in _parse_results
    return self._RESP2_MODULE_CALLBACKS[cmd](res, **kwargs)
/usr/local/Caskroom/miniconda/base/envs/test/lib/python3.7/site-packages/redis/commands/search/commands.py:98: in _parse_profile
    with_scores=query._with_scores,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <[AttributeError("'Result' object has no attribute 'total'") raised in repr()] Result object at 0x7fdd7050aa50>
res = 3, hascontent = True, duration = 38.774967193603516, has_payload = False
with_scores = False

    def __init__(
        self, res, hascontent, duration=0, has_payload=False, with_scores=False
    ):
        """
        - **snippets**: An optional dictionary of the form
        {field: snippet_size} for snippet formatting
        """

>       self.total = res[0]
E       TypeError: 'int' object is not subscriptable

/usr/local/Caskroom/miniconda/base/envs/test/lib/python3.7/site-packages/redis/commands/search/result.py:19: TypeError
xRay2016 commented 1 week ago

I check the response of command, it matches the format in https://redis.io/docs/latest/commands/ft.profile/