Skip to content

Fix Middleware Chain to Allow Awaiting Final Logic Result #2213

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
23 changes: 9 additions & 14 deletions libraries/botbuilder-core/botbuilder/core/turn_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,15 @@ async def _emit(self, plugins, arg, logic):

async def emit_next(i: int):
context = self
try:
if i < len(handlers):

async def next_handler():
await emit_next(i + 1)

await handlers[i](context, arg, next_handler)

except Exception as error:
raise error

await emit_next(0)
# logic does not use parentheses because it's a coroutine
return await logic
if i < len(handlers):
try:
return await handlers[i](context, arg, lambda: emit_next(i + 1))
except Exception as error:
raise error
else:
return await logic

return await emit_next(0)

async def send_trace_activity(
self, name: str, value: object = None, value_type: str = None, label: str = None
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-core/tests/test_turn_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ async def update_handler(context, activity, next_handler_coroutine):
assert context is not None
assert activity.id == activity_id
assert activity.conversation.id == ACTIVITY.conversation.id
await next_handler_coroutine()
return await next_handler_coroutine()

context.on_update_activity(update_handler)
new_activity = MessageFactory.text("test text")
Expand Down