Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expire method fails when using DEFAULT_TIMEOUT #724

Closed
axelstudios opened this issue Feb 9, 2024 · 1 comment · Fixed by #726
Closed

Expire method fails when using DEFAULT_TIMEOUT #724

axelstudios opened this issue Feb 9, 2024 · 1 comment · Fixed by #726

Comments

@axelstudios
Copy link

axelstudios commented Feb 9, 2024

Describe the bug
When attempting to reset the TTL of a key, calling cache.expire(key, DEFAULT_TIMEOUT) fails, because the stubbed DEFAULT_TIMEOUT = object() is passed through to redis-py rather than an integer.

This does not affect the touch method, because that one explicitly updates the timeout with:

if timeout is DEFAULT_TIMEOUT:
    timeout = self._backend.default_timeout

To Reproduce
Steps to reproduce the behavior:

  1. Run cache.expire(key, DEFAULT_TIMEOUT)

Expected behavior
The default timeout should be replaced by the backend integer default timeout before sending the value to redis-py

Stack trace

Traceback (most recent call last):
  File "my_project/utils/cache.py", line 55, in get_cache
    django_cache.expire(progress_key, DEFAULT_TIMEOUT)
  File "venv/lib/site-packages/django_redis/cache.py", line 29, in _decorator
    return method(self, *args, **kwargs)
  File "venv/lib/site-packages/django_redis/cache.py", line 162, in expire
    return self.client.expire(*args, **kwargs)
  File "venv/lib/site-packages/django_redis/client/default.py", line 289, in expire
    return client.expire(key, timeout)
  File "venv/lib/site-packages/redis/client.py", line 1591, in expire
    return self.execute_command('EXPIRE', name, time)
  File "venv/lib/site-packages/redis/client.py", line 900, in execute_command
    conn.send_command(*args)
  File "venv/lib/site-packages/redis/connection.py", line 725, in send_command
    self.send_packed_command(self.pack_command(*args),
  File "venv/lib/site-packages/redis/connection.py", line 775, in pack_command
    for arg in imap(self.encoder.encode, args):
  File "venv/lib/site-packages/redis/connection.py", line 119, in encode
    raise DataError("Invalid input of type: '%s'. Convert to a "
redis.exceptions.DataError: Invalid input of type: 'object'. Convert to a bytes, string, int or float first.

Environment (please complete the following information):

  • Python version: 3.9
  • Django Redis Version: 5.4.0
  • Django Version: 3.2
@sauravsharma1998
Copy link

@WisdomPill @axelstudios I am creating PR for for this fix.

sauravsharma1998 pushed a commit to sauravsharma1998/django-redis that referenced this issue Feb 16, 2024
sauravsharma1998 pushed a commit to sauravsharma1998/django-redis that referenced this issue Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants