From 2592b20d68a55c3b53f116410dfd515b995b7881 Mon Sep 17 00:00:00 2001 From: Brian Maissy Date: Thu, 24 Oct 2019 09:29:00 +0300 Subject: Pipeline.execute() doesn't short-circuit on empty command stack if it is watching keys --- redis/client.py | 2 +- tests/test_pipeline.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/redis/client.py b/redis/client.py index df1ebfd..1e5ca02 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3670,7 +3670,7 @@ class Pipeline(Redis): def execute(self, raise_on_error=True): "Execute all the commands in the current pipeline" stack = self.command_stack - if not stack: + if not stack and not self.watching: return [] if self.scripts: self.load_scripts() diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 2e2507a..264a64f 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -191,6 +191,19 @@ class TestPipeline(object): assert not pipe.watching + def test_watch_failure_in_empty_transaction(self, r): + r['a'] = 1 + r['b'] = 2 + + with r.pipeline() as pipe: + pipe.watch('a', 'b') + r['b'] = 3 + pipe.multi() + with pytest.raises(redis.WatchError): + pipe.execute() + + assert not pipe.watching + def test_unwatch(self, r): r['a'] = 1 r['b'] = 2 -- cgit v1.2.1