From c5a1ef17345e17269085e7f72858ac9bd6faf1dd Mon Sep 17 00:00:00 2001 From: th3hamm0r Date: Mon, 3 Jan 2022 04:44:42 +0100 Subject: [PATCH] Fixed wrong keys used to WATCH dependencies (#1605) This bug has opened a lot of possible race-conditions, since the watch-logic from redis did not fail anymore, if dependencies have been changed in parallel. --- rq/job.py | 6 ++++-- tests/test_job.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rq/job.py b/rq/job.py index 8fef0f3a..4cb12528 100644 --- a/rq/job.py +++ b/rq/job.py @@ -485,7 +485,8 @@ class Job: connection = pipeline if pipeline is not None else self.connection if watch and self._dependency_ids: - connection.watch(*self._dependency_ids) + connection.watch(*[self.key_for(dependency_id) + for dependency_id in self._dependency_ids]) jobs = [job for job in self.fetch_many(self._dependency_ids, connection=self.connection, serializer=self.serializer) @@ -970,7 +971,8 @@ class Job: connection = pipeline if pipeline is not None else self.connection if pipeline is not None: - connection.watch(*self.dependency_ids) + connection.watch(*[self.key_for(dependency_id) + for dependency_id in self._dependency_ids]) dependencies_ids = {_id.decode() for _id in connection.smembers(self.dependencies_key)} diff --git a/tests/test_job.py b/tests/test_job.py index 185c5ecf..fecf5bb6 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -998,7 +998,7 @@ class TestJob(RQTestCase): pipeline.multi() with self.assertRaises(WatchError): - self.testconn.set(dependency_job.id, 'somethingelsehappened') + self.testconn.set(Job.key_for(dependency_job.id), 'somethingelsehappened') pipeline.touch(dependency_job.id) pipeline.execute()