Skip to content

Corrected DialogContext.cancel_all_dialogs #1727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 25 additions & 37 deletions libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down