django-redis icon indicating copy to clipboard operation
django-redis copied to clipboard

Default client does not pass `blocking` kwarg through lock method

Open thenewguy opened this issue 3 years ago • 11 comments

Traceback:

    lock = cache_redis_lock.lock(name, blocking=False, timeout=240)
  File "/home/vagrant/.tox/py37/lib/python3.7/site-packages/django_redis/cache.py", line 31, in _decorator
    return method(self, *args, **kwargs)
  File "/home/vagrant/.tox/py37/lib/python3.7/site-packages/django_redis/cache.py", line 173, in lock
    return self.client.lock(*args, **kwargs)
TypeError: lock() got an unexpected keyword argument 'blocking'

This should be an acceptable kwarg per https://github.com/redis/redis-py/blob/3.5.3/redis/lock.py#L74 and the threading.Lock implementation.

It is not listed in the lock signature on the default client at https://github.com/jazzband/django-redis/blob/5.0.0/django_redis/client/default.py#L329

thenewguy avatar Mar 30 '22 14:03 thenewguy

That is a redis-py issue which should be taken care of there.

WisdomPill avatar Mar 30 '22 14:03 WisdomPill

Can you look again - it appears to be an error in the client lock() method. The redis-py lock allows the parameter. I checkd before submitting the issue and linked the link in the issue

thenewguy avatar Mar 30 '22 15:03 thenewguy

@WisdomPill ^

thenewguy avatar Mar 30 '22 15:03 thenewguy

DefaultClient.lock does not accept **kwargs and does not list blocking as an argument it accepts in the signature

thenewguy avatar Mar 30 '22 15:03 thenewguy

sorry, I thought you were using lock as context manager

WisdomPill avatar Mar 30 '22 15:03 WisdomPill

I would add blocking argument along with *args and **kwargs to that function, would you be up for a PR?

WisdomPill avatar Mar 30 '22 15:03 WisdomPill

Actually, if you are calling lock.acquire() then you can pass the blocking parameter.

The client.lock() in redis-py does not allow blocking parameter to be passed so the only way is to use lock.acquire().

We cannot use *args and **kwargs because they are not going to solve the problem

WisdomPill avatar Apr 18 '22 08:04 WisdomPill

I would suggest to open an issue and maybe a PR in redis-py first and then make changes to django-redis, otherwise the desired behavior is not possible.

WisdomPill avatar Apr 18 '22 08:04 WisdomPill

@WisdomPill that's not true: https://github.com/redis/redis-py/blob/master/redis/client.py#L1099

Therefore, I think your PR will solve it.

aqeelat avatar Jun 28 '22 10:06 aqeelat

Hello @AqeelAT,

I actually made the pr not long ago to be able to proceed with #603 in redis/redis-py#2137 :) But unfortunately I did not get back to #603 just yet

WisdomPill avatar Jun 28 '22 10:06 WisdomPill

Oh I just noticed that you're the one who made https://github.com/redis/redis-py/pull/2137. We could definitely benefit from #603 I think it is ready to be merged.

aqeelat avatar Jun 28 '22 11:06 aqeelat

no update on this ?

tevariou avatar Oct 02 '24 14:10 tevariou