Skip to content

Fix slack_bolt engine UnboundLocalError on workflow/bot messages (#68105)#69439

Open
dwoz wants to merge 1 commit into
saltstack:3006.xfrom
dwoz:fix/issue-68105
Open

Fix slack_bolt engine UnboundLocalError on workflow/bot messages (#68105)#69439
dwoz wants to merge 1 commit into
saltstack:3006.xfrom
dwoz:fix/issue-68105

Conversation

@dwoz

@dwoz dwoz commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Stops the slack_bolt engine from crashing when a Slack workflow (or any bot) posts a message to a monitored channel. Such messages have subtype: "bot_message" and carry bot_id and username instead of a user field; 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 assignment inside just_data() and the entire engine could not be started:

File ".../salt/engines/slack_bolt_engine.py", line 607, in just_data
    "user_id": user_id,
UnboundLocalError: local variable 'user_id' referenced before assignment

The just_data helper expected every message to carry one of m_data["user"], m_data["message"]["user"], or m_data["comment"]["user"]. Bot-posted messages carry none of those, so user_id was referenced unbound.

New Behavior

just_data() now pre-binds user_id/user_name to None and handles subtype: bot_message by falling back to bot_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?

  • Docs (no user-facing docs change — internal robustness fix)
  • Changelog (changelog/68105.fixed.md)
  • Tests written/updated (tests/pytests/unit/engines/test_slack_bolt_engine.py::test_generate_triggered_messages_bot_message_68105)

Commits signed with GPG?

No

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant