Skip to content

Commit d71c6ed

Browse files
authored
Corrected DialogContext.cancel_all_dialogs (#1727)
1 parent d05e62e commit d71c6ed

File tree

1 file changed

+25
-37
lines changed

1 file changed

+25
-37
lines changed

libraries/botbuilder-dialogs/botbuilder/dialogs/dialog_context.py

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -219,50 +219,38 @@ async def cancel_all_dialogs(
219219
:param event_value:
220220
:return:
221221
"""
222-
# pylint: disable=too-many-nested-blocks
223222
try:
224-
if cancel_parents is None:
225-
event_name = event_name or DialogEvents.cancel_dialog
226-
227-
if self.stack or self.parent:
228-
# Cancel all local and parent dialogs while checking for interception
229-
notify = False
230-
dialog_context = self
231-
232-
while dialog_context:
233-
if dialog_context.stack:
234-
# Check to see if the dialog wants to handle the event
235-
if notify:
236-
event_handled = await dialog_context.emit_event(
237-
event_name,
238-
event_value,
239-
bubble=False,
240-
from_leaf=False,
241-
)
242-
243-
if event_handled:
244-
break
245-
246-
# End the active dialog
247-
await dialog_context.end_active_dialog(
248-
DialogReason.CancelCalled
249-
)
250-
else:
251-
dialog_context = (
252-
dialog_context.parent if cancel_parents else None
223+
event_name = event_name or DialogEvents.cancel_dialog
224+
if self.stack or self.parent:
225+
# Cancel all local and parent dialogs while checking for interception
226+
notify = False
227+
dialog_context = self
228+
229+
while dialog_context:
230+
if dialog_context.stack:
231+
# Check to see if the dialog wants to handle the event
232+
if notify:
233+
event_handled = await dialog_context.emit_event(
234+
event_name, event_value, bubble=False, from_leaf=False,
253235
)
254236

255-
notify = True
237+
if event_handled:
238+
break
239+
240+
# End the active dialog
241+
await dialog_context.end_active_dialog(
242+
DialogReason.CancelCalled
243+
)
244+
else:
245+
dialog_context = (
246+
dialog_context.parent if cancel_parents else None
247+
)
256248

257-
return DialogTurnResult(DialogTurnStatus.Cancelled)
258-
# Stack was empty and no parent
259-
return DialogTurnResult(DialogTurnStatus.Empty)
249+
notify = True
260250

261-
if self.stack:
262-
while self.stack:
263-
await self.end_active_dialog(DialogReason.CancelCalled)
264251
return DialogTurnResult(DialogTurnStatus.Cancelled)
265252

253+
# Stack was empty and no parent
266254
return DialogTurnResult(DialogTurnStatus.Empty)
267255
except Exception as err:
268256
self.__set_exception_context_data(err)

0 commit comments

Comments
 (0)