From c2bec19b094bdd536d4c42f184983fabdabe7652 Mon Sep 17 00:00:00 2001 From: Simon Blanchard Date: Thu, 8 Jun 2023 16:55:58 +0800 Subject: [PATCH] pass exc_string as an argument to log (#1934) * pass exc_string as an argument to log * fix test of exception log by accessing right arg * fix black "error" --- rq/worker.py | 4 +++- tests/test_worker.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rq/worker.py b/rq/worker.py index 267f9c1..44d5204 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -1498,7 +1498,9 @@ class Worker(BaseWorker): extra.update({'queue': job.origin, 'job_id': job.id}) # func_name - self.log.error('[Job %s]: exception raised while executing (%s)\n' + exc_string, job.id, func_name, extra=extra) + self.log.error( + '[Job %s]: exception raised while executing (%s)\n%s', job.id, func_name, exc_string, extra=extra + ) for handler in self._exc_handlers: self.log.debug('Invoking exception handler %s', handler) diff --git a/tests/test_worker.py b/tests/test_worker.py index 6b6d3d5..8f0c064 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -268,7 +268,7 @@ class TestWorker(RQTestCase): w.perform_job(job, queue) # An exception should be logged here at ERROR level - self.assertIn("Traceback", mock_logger_error.call_args[0][0]) + self.assertIn("Traceback", mock_logger_error.call_args[0][3]) def test_heartbeat(self): """Heartbeat saves last_heartbeat"""