From a7039c815e338c003dfb1bc8b39724e0671d25eb Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Tue, 11 Aug 2020 14:04:15 +0200 Subject: [PATCH] queue_processors: Fix UnboundLocalError in QueueProcessingWorker. consume_time_seconds wasn't properly defined at the beginning, so when a BaseException that isn't a subclass of Exception is thrown, the finally: block could be entered with it still undefined. --- zerver/worker/queue_processors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py index 0b06303ab9..bcc99f8e82 100644 --- a/zerver/worker/queue_processors.py +++ b/zerver/worker/queue_processors.py @@ -212,14 +212,14 @@ class QueueProcessingWorker(ABC): def do_consume(self, consume_func: Callable[[List[Dict[str, Any]]], None], events: List[Dict[str, Any]]) -> None: + consume_time_seconds: Optional[float] = None try: time_start = time.time() consume_func(events) - consume_time_seconds: Optional[float] = time.time() - time_start + consume_time_seconds = time.time() - time_start self.consumed_since_last_emptied += len(events) except Exception: self._handle_consume_exception(events) - consume_time_seconds = None finally: flush_per_request_caches() reset_queries()