Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/724.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hotfix for timeout=DEFAULT_TIMEOUT in expire and pexpire
6 changes: 6 additions & 0 deletions django_redis/client/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ def expire(
version: Optional[int] = None,
client: Optional[Redis] = None,
) -> bool:
if timeout is DEFAULT_TIMEOUT:
timeout = self._backend.default_timeout # type: ignore

if client is None:
client = self.get_client(write=True)

Expand All @@ -315,6 +318,9 @@ def pexpire(
version: Optional[int] = None,
client: Optional[Redis] = None,
) -> bool:
if timeout is DEFAULT_TIMEOUT:
timeout = self._backend.default_timeout # type: ignore

if client is None:
client = self.get_client(write=True)

Expand Down
11 changes: 11 additions & 0 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest
from django.core.cache import caches
from django.core.cache.backends.base import DEFAULT_TIMEOUT
from django.test import override_settings
from pytest_django.fixtures import SettingsWrapper
from pytest_mock import MockerFixture
Expand Down Expand Up @@ -606,6 +607,11 @@ def test_expire(self, cache: RedisCache):
assert pytest.approx(ttl) == 20
assert cache.expire("not-existent-key", 20) is False

def test_expire_with_default_timeout(self, cache: RedisCache):
cache.set("foo", "bar", timeout=None)
assert cache.expire("foo", DEFAULT_TIMEOUT) is True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you try to expire a non existing key as well?

assert cache.expire("not-existent-key", DEFAULT_TIMEOUT) is False

def test_pexpire(self, cache: RedisCache):
cache.set("foo", "bar", timeout=None)
assert cache.pexpire("foo", 20500) is True
Expand All @@ -614,6 +620,11 @@ def test_pexpire(self, cache: RedisCache):
assert pytest.approx(ttl, 10) == 20500
assert cache.pexpire("not-existent-key", 20500) is False

def test_pexpire_with_default_timeout(self, cache: RedisCache):
cache.set("foo", "bar", timeout=None)
assert cache.pexpire("foo", DEFAULT_TIMEOUT) is True
assert cache.pexpire("not-existent-key", DEFAULT_TIMEOUT) is False

def test_pexpire_at(self, cache: RedisCache):
# Test settings expiration time 1 hour ahead by datetime.
cache.set("foo", "bar", timeout=None)
Expand Down