Method setDecoder is not working
bentsku opened this issue · 0 comments
Hello,
The method setDecoder is not working properly, if you use it after initialising your Client instance, it won't be used in the callbacks.
Passing the decoder as a parameter when initialising the Client instance works as expected.
I believe it is because we set the callbacks in the __init__
method, and when we set the new decoder, we reassign self._decode
with the new decoder decode
method, but the callbacks are still pointing to the old function.
Those callbacks are not recreated with the set_response_callback
method.
Lines 52 to 71 in b57f8c6
I guess several fixes are possible, having _decode
being a declared method of the class, which would be calling the _decode_function
property (I don't like the name, what should it be ?) that would be set in the setDecoder
method. The callbacks would always be pointing to the right method.
A quick fix that would also be fixing the TypeError for every command would be in the form of this snippet.
class Client(StrictRedis):
_encoder = None
_encode = None
_decoder = None
_decode_function = None
[...]
def _decode(self, s, *args, **kwargs):
try:
return self._decode_function(s, *args, **kwargs)
except TypeError:
if s is not None:
raise
return None
This would fix the callback problem (tested). I can open a pull request if you'd like this fix.
Thank you