Skip to content

Expire method fails when using DEFAULT_TIMEOUT #724

@axelstudios

Description

@axelstudios

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions