From d0e832181f4a25705ba52d92f3634ed5bb6b2d5a Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Sun, 8 Jan 2023 13:11:33 +0700 Subject: [PATCH] Don't log job exceptions twice (#1746) * Don't log job exceptions twice * Preserve traceback while encountering deserialization error --- rq/worker.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rq/worker.py b/rq/worker.py index e44aa9f..7841faa 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -1164,6 +1164,7 @@ class Worker: def handle_exception(self, job: 'Job', *exc_info): """Walks the exception handler stack to delegate exception handling.""" + exc_string = ''.join(traceback.format_exception(*exc_info)) # If the job cannot be deserialized, it will raise when func_name or @@ -1175,14 +1176,17 @@ class Worker: 'arguments': job.args, 'kwargs': job.kwargs, } + func_name = job.func_name except DeserializationError: extra = {} + func_name = '' # the properties below should be safe however extra.update({'queue': job.origin, 'job_id': job.id}) - + # func_name - self.log.error(exc_string, exc_info=True, extra=extra) + self.log.error(f'[Job {job.id}]: exception raised while executing ({func_name})\n' + exc_string, + extra=extra) for handler in self._exc_handlers: self.log.debug('Invoking exception handler %s', handler)