Grokzen / redis-py-cluster

Python cluster client for the official redis cluster. Redis 3.0+.
https://redis-py-cluster.readthedocs.io/
MIT License
1.1k stars 315 forks source link

get_slowlog shows TypeError: <lambda>() got an unexpected keyword argument 'decode_responses' #415

Closed edwardwufast closed 3 years ago

edwardwufast commented 4 years ago

Version: redis==3.5.3 redis-py-cluster==2.1.0

Platform: Python 3.8.3 on Amazon Linux 2 4.14.192-147.314.amzn2.x86_64

Description:

Here is the sample code:

from rediscluster import RedisCluster

startup_nodes = [{"host": "test.ryi7vr.clustercfg.apne1.cache.amazonaws.com", "port": "6379"}]
client = RedisCluster(startup_nodes=startup_nodes, decode_responses=True, skip_full_coverage_check=True, readonly_mode=True)
client.slowlog_get(num=1000)

The result:

Traceback (most recent call last):
  File "sample.py", line 6, in <module>
    client.slowlog_get(num=1000)
  File "/home/ec2-user/.pyenv/versions/env/lib/python3.8/site-packages/redis/client.py", line 1466, in slowlog_get
    return self.execute_command(*args, decode_responses=decode_responses)
  File "/home/ec2-user/.pyenv/versions/env/lib/python3.8/site-packages/rediscluster/client.py", line 552, in execute_command
    return self._execute_command(*args, **kwargs)
  File "/home/ec2-user/.pyenv/versions/env/lib/python3.8/site-packages/rediscluster/client.py", line 578, in _execute_command
    return self._execute_command_on_nodes(node, *args, **kwargs)
  File "/home/ec2-user/.pyenv/versions/env/lib/python3.8/site-packages/rediscluster/client.py", line 738, in _execute_command_on_nodes
    return self._merge_result(command, res, **kwargs)
  File "/home/ec2-user/.pyenv/versions/env/lib/python3.8/site-packages/rediscluster/client.py", line 512, in _merge_result
    return self.result_callbacks[command](command, res, **kwargs)
TypeError: <lambda>() got an unexpected keyword argument 'decode_responses'

I checked it with pdb. It seem like the lambda function self.result_callbacks['SLOWLOG GET'] did not support 'decode_responses'. Once I remove "**kwargs" , it works. Could you fix this ?

[ec2-user@ip-172-31-29-59 redis_stress]$ python sample.py
> /home/ec2-user/.pyenv/versions/env/lib/python3.8/site-packages/rediscluster/client.py(512)_merge_result()
-> return self.result_callbacks[command](command, res, **kwargs)

(Pdb) a
self = RedisCluster<zoetop-test-56.ryi7vr.clustercfg.apne1.cache.amazonaws.com:6379>
command = 'SLOWLOG GET'
res = {'172.31.29.64:6379': [{'id': 22, 'start_time': 1604856291, 'duration': 17731, 'command': 'get key'}, {'id': 21, 'start_time': 1604852172, 'duration': 17027, 'command': 'get key'}, {'id': 20, 'start_time': 1604850962, 'duration': 12842, 'command': 'get key'}, {'id': 19, 'start_time': 1604636272, 'duration': 12011, 'command': 'get key'}, {'id': 18, 'start_time': 1604632787, 'duration': 12052, 'command': 'get key'}, {'id': 17, 'start_time': 1604628411, 'duration': 20069, 'command': 'get key'}, {'id': 16, 'start_time': 1604621443, 'duration': 20950, 'command': 'get key'}, {'id': 15, 'start_time': 1604620545, 'duration': 12013, 'command': 'get key'}, {'id': 14, 'start_time': 1604620305, 'duration': 10310, 'command': 'get key'}, {'id': 13, 'start_time': 1604619998, 'duration': 16001, 'command': 'get key'}, {'id': 12, 'start_time': 1604618571, 'duration': 16040, 'command': 'get key'}, {'id': 11, 'start_time': 1604611290, 'duration': 22544, 'command': 'get key'}, {'id': 10, 'start_time': 1604597622, 'duration': 12012, 'command': 'get key'}, {'id': 9, 'start_time': 1604593795, 'duration': 19289, 'command': 'get key'}, {'id': 8, 'start_time': 1604593185, 'duration': 13071, 'command': 'get key'}, {'id': 7, 'start_time': 1604592004, 'duration': 16021, 'command': 'get key'}, {'id': 6, 'start_time': 1604587551, 'duration': 10762, 'command': 'get key'}, {'id': 5, 'start_time': 1604586459, 'duration': 20013, 'command': 'get key'}, {'id': 4, 'start_time': 1604585145, 'duration': 12013, 'command': 'get key'}], '172.31.38.213:6379': [], '172.31.8.218:6379': [], '172.31.3.115:6379': [], '172.31.44.113:6379': [], '172.31.16.139:6379': [], '172.31.36.193:6379': [], '172.31.1.242:6379': [], '172.31.28.51:6379': []}
kwargs = {'decode_responses': True}

(Pdb) self.result_callbacks[command](command, res, **kwargs)
*** TypeError: <lambda>() got an unexpected keyword argument 'decode_responses'

(Pdb) self.result_callbacks[command](command, res)
{'172.31.29.64:6379': [{'id': 22, 'start_time': 1604856291, 'duration': 17731, 'command': 'get key'}, {'id': 21, 'start_time': 1604852172, 'duration': 17027, 'command': 'get key'}, {'id': 20, 'start_time': 1604850962, 'duration': 12842, 'command': 'get key'}, {'id': 19, 'start_time': 1604636272, 'duration': 12011, 'command': 'get key'}, {'id': 18, 'start_time': 1604632787, 'duration': 12052, 'command': 'get key'}, {'id': 17, 'start_time': 1604628411, 'duration': 20069, 'command': 'get key'}, {'id': 16, 'start_time': 1604621443, 'duration': 20950, 'command': 'get key'}, {'id': 15, 'start_time': 1604620545, 'duration': 12013, 'command': 'get key'}, {'id': 14, 'start_time': 1604620305, 'duration': 10310, 'command': 'get key'}, {'id': 13, 'start_time': 1604619998, 'duration': 16001, 'command': 'get key'}, {'id': 12, 'start_time': 1604618571, 'duration': 16040, 'command': 'get key'}, {'id': 11, 'start_time': 1604611290, 'duration': 22544, 'command': 'get key'}, {'id': 10, 'start_time': 1604597622, 'duration': 12012, 'command': 'get key'}, {'id': 9, 'start_time': 1604593795, 'duration': 19289, 'command': 'get key'}, {'id': 8, 'start_time': 1604593185, 'duration': 13071, 'command': 'get key'}, {'id': 7, 'start_time': 1604592004, 'duration': 16021, 'command': 'get key'}, {'id': 6, 'start_time': 1604587551, 'duration': 10762, 'command': 'get key'}, {'id': 5, 'start_time': 1604586459, 'duration': 20013, 'command': 'get key'}, {'id': 4, 'start_time': 1604585145, 'duration': 12013, 'command': 'get key'}], '172.31.38.213:6379': [], '172.31.8.218:6379': [], '172.31.3.115:6379': [], '172.31.44.113:6379': [], '172.31.16.139:6379': [], '172.31.36.193:6379': [], '172.31.1.242:6379': [], '172.31.28.51:6379': []}
Grokzen commented 4 years ago

Hmm, interesting. I will have a look at it why that argument is persisted down there. Will have to look at all other methods to see who might need that kwargs there or not. But good reproducable example tho. I am a bit surprised that unittests did not catch this really O.o have to look at that as well. My guess would be the unittest configuration do not set that flag or something, will see what i can dig up.

Grokzen commented 3 years ago

Fixed in 4961bd86f176c2d6667bca1eac982f033710a2c4