#34212: Redis cache client uses a read connection for incr operation
-------------------------------------+-------------------------------------
Reporter: Ilari | Owner: nobody
Sahi |
Type: Bug | Status: new
Component: Core | Version: 4.1
(Cache system) |
Severity: Normal | Keywords: redis cache incr
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
RedisCacheClient uses a read only connection for the incr operation:
https://github.com/django/django/blob/main/django/core/cache/backends/redis.py#L133
However, it is a write operation, at least according to Amazon ElastiCache
Redis server. redis-py raises a ReadOnlyError exception:
{{{
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-
packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/usr/local/lib/python3.10/site-
packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)
File "/usr/local/lib/python3.10/site-
packages/django/views/generic/base.py", line 103, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.10/site-
packages/django/utils/decorators.py", line 46, in _wrapper
return bound_method(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/ratelimit/decorators.py",
line 18, in _wrapped
ratelimited = is_ratelimited(request=request, group=group, fn=fn,
File "/usr/local/lib/python3.10/site-packages/ratelimit/core.py", line
119, in is_ratelimited
usage = get_usage(request, group, fn, key, rate, method, increment)
File "/usr/local/lib/python3.10/site-packages/ratelimit/core.py", line
205, in get_usage
count = cache.incr(cache_key)
File "/usr/local/lib/python3.10/site-
packages/django/core/cache/backends/redis.py", line 214, in incr
return self._cache.incr(key, delta)
File "/usr/local/lib/python3.10/site-
packages/django/core/cache/backends/redis.py", line 136, in incr
return client.incr(key, delta)
File "/usr/local/lib/python3.10/site-packages/redis/commands/core.py",
line 1852, in incrby
return self.execute_command("INCRBY", name, amount)
File "/usr/local/lib/python3.10/site-packages/redis/client.py", line
1258, in execute_command
return conn.retry.call_with_retry(
File "/usr/local/lib/python3.10/site-packages/redis/retry.py", line 46,
in call_with_retry
return do()
File "/usr/local/lib/python3.10/site-packages/redis/client.py", line
1259, in <lambda>
lambda: self._send_command_parse_response(
File "/usr/local/lib/python3.10/site-packages/redis/client.py", line
1235, in _send_command_parse_response
return self.parse_response(conn, command_name, **options)
File "/usr/local/lib/python3.10/site-packages/redis/client.py", line
1275, in parse_response
response = connection.read_response()
File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line
827, in read_response
raise response
Exception Type: ReadOnlyError at ...
Exception Value: You can't write against a read only replica.
}}}
In incr-function, get_client should be called with write argument as True.
--
Ticket URL: <https://code.djangoproject.com/ticket/34212>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701851059b4f4-70e962e2-baed-4f4b-9772-9713b680aa0b-000000%40eu-central-1.amazonses.com.