Fix slack_bolt engine UnboundLocalError on workflow/bot messages (#68105)#69439
Open
dwoz wants to merge 1 commit into
Open
Fix slack_bolt engine UnboundLocalError on workflow/bot messages (#68105)#69439dwoz wants to merge 1 commit into
dwoz wants to merge 1 commit into
Conversation
A Slack workflow that posts to a monitored channel produces a message with subtype "bot_message" and no "user" field; the slack_bolt engine's just_data() helper falls through every existing branch without binding user_id, then references it in the returned dict and raises UnboundLocalError, crashing the engine. Pre-bind user_id and user_name to None and add a bot_message branch that uses bot_id and username from the message so workflow/bot posts flow through the engine instead of taking it down. Fixes saltstack#68105
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Stops the
slack_boltengine from crashing when a Slack workflow (or any bot) posts a message to a monitored channel. Such messages havesubtype: "bot_message"and carrybot_idandusernameinstead of auserfield; the engine now uses those as fallbacks so the message flows through normally.What issues does this PR fix or reference?
Fixes #68105
Previous Behavior
When a workflow posted to a channel watched by the slack_bolt engine, the engine raised
UnboundLocalError: local variable 'user_id' referenced before assignmentinsidejust_data()and the entire engine could not be started:The
just_datahelper expected every message to carry one ofm_data["user"],m_data["message"]["user"], orm_data["comment"]["user"]. Bot-posted messages carry none of those, souser_idwas referenced unbound.New Behavior
just_data()now pre-bindsuser_id/user_nametoNoneand handlessubtype: bot_messageby falling back tobot_id/username. Workflow and bot messages no longer crash the engine and are propagated through to the caller with bot identity attached.Merge requirements satisfied?
changelog/68105.fixed.md)tests/pytests/unit/engines/test_slack_bolt_engine.py::test_generate_triggered_messages_bot_message_68105)Commits signed with GPG?
No