From 35b7e09a57a1b7e2931d90e4b13858b68cee97cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Wed, 10 May 2023 10:25:41 +0000 Subject: Kristjan/issue #2754: Add missing argument to SentinelManagedConnection.read_response() (#2756) * Increase timeout for a test which would hang completely if failing. Timeouts in virtualized CI backends can occasionally fail if too short. * add "disconnect_on_error" argument to SentinelManagedConnection * update Changes * lint --- CHANGES | 1 + redis/asyncio/sentinel.py | 3 +++ redis/sentinel.py | 10 ++++++++-- tests/test_asyncio/test_commands.py | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 4917980..1e03453 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,4 @@ + * Fix #2754, adding a missing argument to SentinelManagedConnection * Fix `xadd` command to accept non-negative `maxlen` including 0 * Revert #2104, #2673, add `disconnect_on_error` option to `read_response()` (issues #2506, #2624) * Add `address_remap` parameter to `RedisCluster` diff --git a/redis/asyncio/sentinel.py b/redis/asyncio/sentinel.py index 9147ed8..501e234 100644 --- a/redis/asyncio/sentinel.py +++ b/redis/asyncio/sentinel.py @@ -67,11 +67,14 @@ class SentinelManagedConnection(Connection): self, disable_decoding: bool = False, timeout: Optional[float] = None, + *, + disconnect_on_error: Optional[float] = True, ): try: return await super().read_response( disable_decoding=disable_decoding, timeout=timeout, + disconnect_on_error=disconnect_on_error, ) except ReadOnlyError: if self.connection_pool.is_master: diff --git a/redis/sentinel.py b/redis/sentinel.py index ac6921a..f9f8f1c 100644 --- a/redis/sentinel.py +++ b/redis/sentinel.py @@ -1,5 +1,6 @@ import random import weakref +from typing import Optional from redis.client import Redis from redis.commands import SentinelCommands @@ -53,9 +54,14 @@ class SentinelManagedConnection(Connection): def connect(self): return self.retry.call_with_retry(self._connect_retry, lambda error: None) - def read_response(self, disable_decoding=False): + def read_response( + self, disable_decoding=False, *, disconnect_on_error: Optional[bool] = False + ): try: - return super().read_response(disable_decoding=disable_decoding) + return super().read_response( + disable_decoding=disable_decoding, + disconnect_on_error=disconnect_on_error, + ) except ReadOnlyError: if self.connection_pool.is_master: # When talking to a master, a ReadOnlyError when likely diff --git a/tests/test_asyncio/test_commands.py b/tests/test_asyncio/test_commands.py index 955b9d4..5cde286 100644 --- a/tests/test_asyncio/test_commands.py +++ b/tests/test_asyncio/test_commands.py @@ -3051,7 +3051,7 @@ class TestRedisCommands: # the task is now sleeping, lets send it an exception task.cancel() # If all is well, the task should finish right away, otherwise fail with Timeout - async with async_timeout(0.1): + async with async_timeout(1.0): await task -- cgit v1.2.1