Skip to content
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

slowlog_get() raises TypeError when decode_responses=True #1238

Closed
jakob-keller opened this issue Nov 5, 2019 · 0 comments · Fixed by #1239
Closed

slowlog_get() raises TypeError when decode_responses=True #1238

jakob-keller opened this issue Nov 5, 2019 · 0 comments · Fixed by #1239

Comments

@jakob-keller
Copy link
Contributor

jakob-keller commented Nov 5, 2019

Version: redis-py 3.3.11 and AWS ElastiCache Redis 5.0.5 (Cluster mode off, 1 shard, 2 nodes)

Platform: Python 3.7.5 on macOS Catalina 10.15.1

Description: Calling slowlog_get() on a redis.Redis client instance with decode_responses=True raises a TypeError:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/.../lib/python3.7/site-packages/redis/client.py", line 1192, in slowlog_get
    return self.execute_command(*args)
  File "/Users/.../lib/python3.7/site-packages/redis/client.py", line 839, in execute_command
    return self.parse_response(conn, command_name, **options)
  File "/Users/.../lib/python3.7/site-packages/redis/client.py", line 859, in parse_response
    return self.response_callbacks[command_name](response, **options)
  File "/Users/.../lib/python3.7/site-packages/redis/client.py", line 397, in parse_slowlog_get
    } for item in response]
  File "/Users/.../lib/python3.7/site-packages/redis/client.py", line 397, in <listcomp>
    } for item in response]
TypeError: sequence item 0: expected a bytes-like object, str found

The command executes just fine when decode_responses=False (default).

As a preliminary work-around, I replaced the type of whitespace used on line 396 in parse_slowlog_get() of client.py (bytes -> str):
'command': ' '.join(item[3]) (remove b)

Of course, this no longer handles the default case (decode_responses=False).

There are various ways to address this issue, including:

  1. Somehow pass the value of decode_responses and substitute b' ' by ' ' where appropriate (is this relevant in other places, too?)
  2. Determine type of list members (bytes vs. str) and use appropriate whitespace type
  3. Optimistically keep the current implementation, but wrap it in a try-except block and retry with alternative implementation on exception

I am leaning towards option 1 and would be willing to create a PR, if it helps. Since I'm a noob here, it would help if you could point me to a similar issue for guidance. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant