From aed39358fe35101b1819ceffd30a4ac56107ef02 Mon Sep 17 00:00:00 2001 From: Manuel Alejandro Paz Cetina Date: Sat, 14 Oct 2023 22:21:20 -0600 Subject: [PATCH] fix: Ensure `_is_processing_a_message` resets on exception --- src/pymessagebus/_commandbus.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pymessagebus/_commandbus.py b/src/pymessagebus/_commandbus.py index 17dd360..7a47484 100644 --- a/src/pymessagebus/_commandbus.py +++ b/src/pymessagebus/_commandbus.py @@ -39,9 +39,13 @@ def handle(self, message: object) -> t.Any: raise api.CommandBusAlreadyProcessingAMessage( f"CommandBus already processing a message when received a '{message.__class__}' one." # pylint: disable=line-too-long ) - self._is_processing_a_message = True - result = self._messagebus.handle(message) - self._is_processing_a_message = False + + try: + self._is_processing_a_message = True + result = self._messagebus.handle(message) + finally: + self._is_processing_a_message = False + return result[0] if self._allow_result else None def has_handler_for(self, message_class: type) -> bool: