Skip to content

Commit e4020bc

Browse files
WilliamBergaminClaude
andauthored
fix(oauth): return the latest sqlite3 installation when saves share a second (#2071)
Co-authored-by: Claude <svc-devxp-claude@slack-corp.com>
1 parent da717a5 commit e4020bc

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

‎slack_sdk/oauth/installation_store/sqlite3/__init__.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def find_bot(
322322
enterprise_id = ?
323323
and
324324
team_id = ?
325-
order by installed_at desc
325+
order by installed_at desc, id desc
326326
limit 1
327327
""",
328328
[self.client_id, enterprise_id or "", team_id or ""],
@@ -425,7 +425,7 @@ def find_installation(
425425
enterprise_id = ?
426426
and
427427
team_id = ?
428-
order by installed_at desc
428+
order by installed_at desc, id desc
429429
limit 1
430430
""",
431431
[self.client_id, enterprise_id or "", team_id],
@@ -446,7 +446,7 @@ def find_installation(
446446
team_id = ?
447447
and
448448
user_id = ?
449-
order by installed_at desc
449+
order by installed_at desc, id desc
450450
limit 1
451451
""",
452452
[self.client_id, enterprise_id or "", team_id, user_id],
@@ -511,7 +511,7 @@ def find_installation(
511511
team_id = ?
512512
and
513513
bot_token is not null
514-
order by installed_at desc
514+
order by installed_at desc, id desc
515515
limit 1
516516
""",
517517
[self.client_id, enterprise_id or "", team_id],

‎tests/slack_sdk/oauth/installation_store/test_sqlite3.py‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,47 @@ def test_issue_1441_mixing_user_and_bot_installations(self):
330330
self.assertIsNone(installation)
331331
installation = store.find_installation(enterprise_id=None, team_id="T111")
332332
self.assertIsNone(installation)
333+
334+
def test_find_returns_latest_save_within_the_same_second(self):
335+
store = SQLite3InstallationStore(database="logs/test.db", client_id="111.222")
336+
store.delete_all(enterprise_id="E333", team_id="T333")
337+
338+
for suffix in ["old", "new"]:
339+
store.save(
340+
Installation(
341+
app_id="A333",
342+
enterprise_id="E333",
343+
team_id="T333",
344+
user_id="U333",
345+
bot_id="B333",
346+
bot_token=f"xoxb-{suffix}",
347+
bot_scopes=["chat:write"],
348+
bot_user_id="U444",
349+
user_token=f"xoxp-{suffix}",
350+
)
351+
)
352+
store.save(
353+
Installation(
354+
app_id="A333",
355+
enterprise_id="E333",
356+
team_id="T333",
357+
user_id="U555",
358+
user_token="xoxp-user-only",
359+
)
360+
)
361+
with store.connect() as conn:
362+
for table in ["slack_installations", "slack_bots"]:
363+
conn.execute(f"update {table} set installed_at = '2026-11-19 10:00:00' where enterprise_id = 'E333'")
364+
365+
bot = store.find_bot(enterprise_id="E333", team_id="T333")
366+
self.assertEqual(bot.bot_token, "xoxb-new")
367+
368+
installation = store.find_installation(enterprise_id="E333", team_id="T333")
369+
self.assertEqual(installation.user_token, "xoxp-user-only")
370+
self.assertEqual(installation.bot_token, "xoxb-new")
371+
372+
installation = store.find_installation(enterprise_id="E333", team_id="T333", user_id="U333")
373+
self.assertEqual(installation.user_token, "xoxp-new")
374+
self.assertEqual(installation.bot_token, "xoxb-new")
375+
376+
store.delete_all(enterprise_id="E333", team_id="T333")

0 commit comments

Comments
 (0)