From 54db2fa8d1af221485870ddf7c5707cd704c73c7 Mon Sep 17 00:00:00 2001 From: Rony Lutsky Date: Sun, 5 Feb 2023 12:41:56 +0200 Subject: [PATCH] Fix - TypeError - accessing None when dequeued result is None (when timeout=None, e.g. in burst mode) (#1793) * fix accessing None when dequeued result is None (burst=True, or timeout=None) * add a test * pr fix * fix tests --- rq/worker.py | 2 +- tests/test_worker.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rq/worker.py b/rq/worker.py index 6d8cc5e..8720504 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -757,8 +757,8 @@ class Worker: serializer=self.serializer, ) if result is not None: - self.log.debug(f"Dequeued job {blue(result[0].id)} from {green(result[1].name)}") job, queue = result + self.log.debug(f"Dequeued job {blue(job.id)} from {green(queue.name)}") job.redis_server_version = self.get_redis_server_version() if self.log_job_description: self.log.info('%s: %s (%s)', green(queue.name), blue(job.description), job.id) diff --git a/tests/test_worker.py b/tests/test_worker.py index e001a95..b0bb3d7 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -634,6 +634,14 @@ class TestWorker(RQTestCase): res.refresh() self.assertIn('JobTimeoutException', as_text(res.exc_info)) + def test_dequeue_job_and_maintain_ttl_non_blocking(self): + """Not passing a timeout should return immediately with None as a result""" + q = Queue() + w = Worker([q]) + + # Put it on the queue with a timeout value + self.assertIsNone(w.dequeue_job_and_maintain_ttl(None)) + def test_worker_sets_result_ttl(self): """Ensure that Worker properly sets result_ttl for individual jobs.""" q = Queue()