File tree Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change
1
+ Fix for Issue 724(expire method fails when using DEFAULT_TIMEOUT)
2
+
3
+ https://github.com/jazzband/django-redis/issues/724
Original file line number Diff line number Diff line change @@ -299,7 +299,11 @@ def expire(
299
299
version : Optional [int ] = None ,
300
300
client : Optional [Redis ] = None ,
301
301
) -> bool :
302
- if timeout is DEFAULT_TIMEOUT :
302
+ # timeout could be of type int|timedelta
303
+ # if timeout is DEFAULT_TIMEOUT or None then
304
+ # use self._backend.default_timeout(django default cache timeout)
305
+
306
+ if (timeout is DEFAULT_TIMEOUT ) or (timeout is None ):
303
307
timeout = self ._backend .default_timeout
304
308
305
309
if client is None :
Original file line number Diff line number Diff line change 7
7
8
8
import pytest
9
9
from django .core .cache import caches
10
+ from django .core .cache .backends .base import DEFAULT_TIMEOUT
10
11
from django .test import override_settings
11
12
from pytest_django .fixtures import SettingsWrapper
12
13
from pytest_mock import MockerFixture
@@ -606,6 +607,10 @@ def test_expire(self, cache: RedisCache):
606
607
assert pytest .approx (ttl ) == 20
607
608
assert cache .expire ("not-existent-key" , 20 ) is False
608
609
610
+ def test_expire_with_default_timeout (self , cache : RedisCache ):
611
+ cache .set ("foo" , "bar" , timeout = None )
612
+ assert cache .expire ("foo" , DEFAULT_TIMEOUT ) is True
613
+
609
614
def test_pexpire (self , cache : RedisCache ):
610
615
cache .set ("foo" , "bar" , timeout = None )
611
616
assert cache .pexpire ("foo" , 20500 ) is True
You can’t perform that action at this time.
0 commit comments