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.
This commit is contained in:
th3hamm0r 2022-01-03 04:44:42 +01:00 committed by GitHub
parent db445f96b2
commit c5a1ef1734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -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)}

View File

@ -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()