Skip to content
Merged
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
8 changes: 4 additions & 4 deletions slack_sdk/oauth/installation_store/sqlite3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def find_bot(
enterprise_id = ?
and
team_id = ?
order by installed_at desc
order by installed_at desc, id desc

@mwbrooks mwbrooks Nov 19, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): SQLAlchemyInstallationStore orders on desc(c.installed_at) alone in find_bot and find_installation (sync and async). MySQL DATETIME is 1 s precision too, so adding desc(c.id) there could be a nice follow-up.

limit 1
""",
[self.client_id, enterprise_id or "", team_id or ""],
Expand Down Expand Up @@ -425,7 +425,7 @@ def find_installation(
enterprise_id = ?
and
team_id = ?
order by installed_at desc
order by installed_at desc, id desc
limit 1
""",
[self.client_id, enterprise_id or "", team_id],
Expand All @@ -446,7 +446,7 @@ def find_installation(
team_id = ?
and
user_id = ?
order by installed_at desc
order by installed_at desc, id desc
limit 1
""",
[self.client_id, enterprise_id or "", team_id, user_id],
Expand Down Expand Up @@ -511,7 +511,7 @@ def find_installation(
team_id = ?
and
bot_token is not null
order by installed_at desc
order by installed_at desc, id desc
limit 1
""",
[self.client_id, enterprise_id or "", team_id],
Expand Down
44 changes: 44 additions & 0 deletions tests/slack_sdk/oauth/installation_store/test_sqlite3.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,47 @@ def test_issue_1441_mixing_user_and_bot_installations(self):
self.assertIsNone(installation)
installation = store.find_installation(enterprise_id=None, team_id="T111")
self.assertIsNone(installation)

def test_find_returns_latest_save_within_the_same_second(self):
store = SQLite3InstallationStore(database="logs/test.db", client_id="111.222")
store.delete_all(enterprise_id="E333", team_id="T333")

for suffix in ["old", "new"]:
store.save(
Installation(
app_id="A333",
enterprise_id="E333",
team_id="T333",
user_id="U333",
bot_id="B333",
bot_token=f"xoxb-{suffix}",
bot_scopes=["chat:write"],
bot_user_id="U444",
user_token=f"xoxp-{suffix}",
)
)
store.save(
Installation(
app_id="A333",
enterprise_id="E333",
team_id="T333",
user_id="U555",
user_token="xoxp-user-only",
)
)
with store.connect() as conn:
for table in ["slack_installations", "slack_bots"]:
conn.execute(f"update {table} set installed_at = '2026-11-19 10:00:00' where enterprise_id = 'E333'")

bot = store.find_bot(enterprise_id="E333", team_id="T333")
self.assertEqual(bot.bot_token, "xoxb-new")

installation = store.find_installation(enterprise_id="E333", team_id="T333")
self.assertEqual(installation.user_token, "xoxp-user-only")
self.assertEqual(installation.bot_token, "xoxb-new")

installation = store.find_installation(enterprise_id="E333", team_id="T333", user_id="U333")
self.assertEqual(installation.user_token, "xoxp-new")
self.assertEqual(installation.bot_token, "xoxb-new")

store.delete_all(enterprise_id="E333", team_id="T333")
Loading