Built-in InstallationStores fail to resolve a valid bot token when both bot and user-only installations co-exist in database tables #1441
Labels
bug
M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented
enhancement
M-T: A feature request for new functionality
oauth
Version: 3x
Milestone
This happens in apps that implement both org-wide bot-scope installs together with individual user-scope installs.
Examples where an app would want to support this: (a) handling "sign in with Slack" using Bolt and
/oauth_redirect
post-auth redirect url; or (b) offering extra user-level functionality to individuals on top of the org-wide more restricted bot-scope functionality, e.g. see this older discussion: linkSteps to reproduce:
SQLAlchemyInstallationStore.find_installation
Expected: we are supposed to find the bot token to respond to the mention.
What actually happens. Error will be logged and the mention event will be ignored, here is why. This query:
python-slack-sdk/slack_sdk/oauth/installation_store/sqlalchemy/__init__.py
Line 263 in 09fb1db
gets us the user token row from Step 2, not the one from Step 1. Why? B/c (a) it's the most recent
installed_at
, and (b) the argumentuser_id
passed to the function isNone
(as happens when using Bolt - e.g. called from here). So at this point we are missing the bot scopes we actually wanted (in order to get the bot respond to the reply).You would think that the following part of the method is directly aimed at this scenario, i.e. it should go the extra step to retrieve the bot token, but since user_id is None, this block is never executed:
python-slack-sdk/slack_sdk/oauth/installation_store/sqlalchemy/__init__.py
Lines 297 to 315 in 09fb1db
As a result, the error is logged (if using the Bolt App):
And thus the user does not get to see any response from the bot.
Moreover, this outcome depends on the order of the installation rows. If someone reinstalls the bot to the workspace, then the mention will now start working because row with the bot token will become the one with the most recent
installed_at
again. If the user then does user-token oauth again, the mention will stop working again. And so on – leading to unpredictable bot behaviour from the users' point of view.The text was updated successfully, but these errors were encountered: