Skip to content

Commit f391938

Browse files
Saurav SharmaSaurav Sharma
authored andcommitted
Testcase and changelog added for issue #724
1 parent b775d0c commit f391938

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

changelog.d/724.fix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix for Issue 724(expire method fails when using DEFAULT_TIMEOUT)
2+
3+
https://github.com/jazzband/django-redis/issues/724

django_redis/client/default.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ def expire(
299299
version: Optional[int] = None,
300300
client: Optional[Redis] = None,
301301
) -> 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):
303307
timeout = self._backend.default_timeout
304308

305309
if client is None:

tests/test_backend.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99
from django.core.cache import caches
10+
from django.core.cache.backends.base import DEFAULT_TIMEOUT
1011
from django.test import override_settings
1112
from pytest_django.fixtures import SettingsWrapper
1213
from pytest_mock import MockerFixture
@@ -606,6 +607,10 @@ def test_expire(self, cache: RedisCache):
606607
assert pytest.approx(ttl) == 20
607608
assert cache.expire("not-existent-key", 20) is False
608609

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+
609614
def test_pexpire(self, cache: RedisCache):
610615
cache.set("foo", "bar", timeout=None)
611616
assert cache.pexpire("foo", 20500) is True

0 commit comments

Comments
 (0)