Repository navigation
fix: preserve context variables in threaded listeners - #1632
noooooooookro wants to merge 1 commit into
Conversation
|
Thanks for the contribution! Before we can merge this, we need @noooooooookro to sign the Salesforce Inc. Contributor License Agreement. |
|
@noooooooookro Could you sign the Salesforce CLA? We need it signed before we can continue with this PR. 🙏 |
mwbrooks
left a comment
There was a problem hiding this comment.
✅ Thanks @noooooooookro for picking up #1267, and congrats on your first contribution to Bolt for Python! 🎉 Wrapping each submit in copy_context().run is the approach discussed on the issue, and it brings the sync runners in line with how asyncio already carries context into tasks. CI is next, we'll get the workflow runs started.
| seen["ack"] = (get_ident(), request_id.get()) | ||
| request_id.set("from-ack") | ||
| ack() | ||
|
|
There was a problem hiding this comment.
praise: Rebinding the value in the ack listener and then checking it from the lazy listener and a third task on the same worker is a great way to prove each callback gets its own copy, not just the middleware value.
Summary
A threaded listener can lose a correlation ID set by middleware. Bolt now copies the current context each time it submits an ack or lazy callback, including Django lazy listeners. If one callback rebinds that ID, the next callback on the same worker still sees the value set by middleware.
Fixes #1267.
Testing
The full suite passed on Linux with Python 3.11 (957 tests). One regression test dispatches a shortcut through a single-worker app and checks that each listener sees the middleware value. A second sends a signed request through the Django adapter and checks its lazy listener.
Category
slack_bolt.Appand/or its core componentsslack_bolt.async_app.AsyncAppand/or its core componentsslack_bolt.adapter/docsRequirements
./scripts/install_all_and_run_tests.shafter making the changes.