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.
* cc: Daniyal Abbasi, Nick Pope (added)
* stage: Unreviewed => Accepted
Comment:
Good catch!
--
Ticket URL: <https://code.djangoproject.com/ticket/34212#comment:1>
* owner: nobody => Leo Tom
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34212#comment:2>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34212#comment:3>
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34212#comment:4>
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34212#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"a1bcdc94da6d597c51b4eca0411a97a6460b482e" a1bcdc94]:
{{{
#!CommitTicketReference repository=""
revision="a1bcdc94da6d597c51b4eca0411a97a6460b482e"
Fixed #34212 -- Made RedisCacheClient.incr() use write connection.
Co-authored-by: Sin-Woo Bang <sinwo...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34212#comment:6>