From c0289bad6b8ee09c86eb371f2bc1d1017ea0ea8b Mon Sep 17 00:00:00 2001 From: Jakob Keller <57402305+jakob-keller@users.noreply.github.com> Date: Wed, 6 Dec 2023 08:54:43 +0100 Subject: [PATCH] Prevent async ClusterPipeline instances from becoming "false-y" in case of empty command stack --- CHANGES | 1 + redis/asyncio/cluster.py | 3 ++- tests/test_asyncio/test_pipeline.py | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 191286d4af..e1496fa15c 100644 --- a/CHANGES +++ b/CHANGES @@ -57,6 +57,7 @@ * Improve error output for master discovery * Make `ClusterCommandsProtocol` an actual Protocol * Add `sum` to DUPLICATE_POLICY documentation of `TS.CREATE`, `TS.ADD` and `TS.ALTER` + * Prevent async ClusterPipeline instances from becoming "false-y" in case of empty command stack (#3061) * 4.1.3 (Feb 8, 2022) * Fix flushdb and flushall (#1926) diff --git a/redis/asyncio/cluster.py b/redis/asyncio/cluster.py index ebc7e4a4cb..6a1753ad19 100644 --- a/redis/asyncio/cluster.py +++ b/redis/asyncio/cluster.py @@ -1429,7 +1429,8 @@ def __exit__(self, exc_type: None, exc_value: None, traceback: None) -> None: self._command_stack = [] def __bool__(self) -> bool: - return bool(self._command_stack) + "Pipeline instances should always evaluate to True on Python 3+" + return True def __len__(self) -> int: return len(self._command_stack) diff --git a/tests/test_asyncio/test_pipeline.py b/tests/test_asyncio/test_pipeline.py index 3d271bf1d0..4b29360d72 100644 --- a/tests/test_asyncio/test_pipeline.py +++ b/tests/test_asyncio/test_pipeline.py @@ -7,7 +7,6 @@ class TestPipeline: - @pytest.mark.onlynoncluster async def test_pipeline_is_true(self, r): """Ensure pipeline instances are not false-y""" async with r.pipeline() as pipe: