From 0cbf95e217eef45741b05f51fe77c2b76d1c8a4b Mon Sep 17 00:00:00 2001 From: tracyboehrer Date: Mon, 21 Jun 2021 15:01:51 -0500 Subject: [PATCH] Corrected DialogContext.cancel_all_dialogs --- .../botbuilder/dialogs/dialog_context.py | 62 ++++++++----------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_context.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_context.py index b10a63978..d2aaa601a 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_context.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_context.py @@ -219,50 +219,38 @@ async def cancel_all_dialogs( :param event_value: :return: """ - # pylint: disable=too-many-nested-blocks try: - if cancel_parents is None: - event_name = event_name or DialogEvents.cancel_dialog - - if self.stack or self.parent: - # Cancel all local and parent dialogs while checking for interception - notify = False - dialog_context = self - - while dialog_context: - if dialog_context.stack: - # Check to see if the dialog wants to handle the event - if notify: - event_handled = await dialog_context.emit_event( - event_name, - event_value, - bubble=False, - from_leaf=False, - ) - - if event_handled: - break - - # End the active dialog - await dialog_context.end_active_dialog( - DialogReason.CancelCalled - ) - else: - dialog_context = ( - dialog_context.parent if cancel_parents else None + event_name = event_name or DialogEvents.cancel_dialog + if self.stack or self.parent: + # Cancel all local and parent dialogs while checking for interception + notify = False + dialog_context = self + + while dialog_context: + if dialog_context.stack: + # Check to see if the dialog wants to handle the event + if notify: + event_handled = await dialog_context.emit_event( + event_name, event_value, bubble=False, from_leaf=False, ) - notify = True + if event_handled: + break + + # End the active dialog + await dialog_context.end_active_dialog( + DialogReason.CancelCalled + ) + else: + dialog_context = ( + dialog_context.parent if cancel_parents else None + ) - return DialogTurnResult(DialogTurnStatus.Cancelled) - # Stack was empty and no parent - return DialogTurnResult(DialogTurnStatus.Empty) + notify = True - if self.stack: - while self.stack: - await self.end_active_dialog(DialogReason.CancelCalled) return DialogTurnResult(DialogTurnStatus.Cancelled) + # Stack was empty and no parent return DialogTurnResult(DialogTurnStatus.Empty) except Exception as err: self.__set_exception_context_data(err)