Skip to content

fix(oauth): return the latest sqlite3 installation when saves share a second - #2071

Open
WilliamBergamin wants to merge 1 commit into
slackapi:mainfrom
WilliamBergamin:fix/sqlite3-installed-at-tie
Open

WilliamBergamin wants to merge 1 commit into
slackapi:mainfrom
WilliamBergamin:fix/sqlite3-installed-at-tie

Conversation

@WilliamBergamin

Copy link
Copy Markdown
Contributor

Summary

This pull request makes SQLite3InstallationStore return the latest installation when two saves land in the same second.

  • save() leaves installed_at to the column default current_timestamp, which has 1 s resolution. Saves in the same second tie on order by installed_at desc, and SQLite picks a tied row in no defined order. Locally, the no-user find_installation and the latest-bot-token merge returned the older row, so a reinstall or token rotation could hand back a stale token.
  • All four lookups now order by installed_at desc, id desc. id is the autoincrement key, so the newest insert wins a tie. There is no schema or data change.
  • Writing Installation.installed_at instead would break existing databases: old rows store TEXT, and SQLite sorts REAL below TEXT. It would also break token rotation, since a rotated installation keeps its original installed_at.

Testing

test_find_returns_latest_save_within_the_same_second saves an old and a new installation plus a user-only one, then forces all rows to the same installed_at. It fails on main (the no-user lookup returns xoxp-old) and passes here. SQLite doesn't define the order of tied rows, so another SQLite build could pass it on main by chance; it stays in as a regression guard.

Category

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs (Documents)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I have signed the Salesforce CLA (required before your PR can be reviewed or merged).
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

🤖 Generated with Claude Code

… second

installed_at defaults to current_timestamp (1 s resolution), so saves in the
same second tie and the lookups could return the older row. Break ties on the
autoincrement id.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@WilliamBergamin WilliamBergamin self-assigned this Nov 19, 2026
@WilliamBergamin WilliamBergamin added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch oauth labels Nov 19, 2026
@WilliamBergamin WilliamBergamin added this to the 3.47.1 milestone Nov 19, 2026
@WilliamBergamin
WilliamBergamin marked this pull request as ready for review November 19, 2026 22:12
@WilliamBergamin
WilliamBergamin requested a review from a team as a code owner November 19, 2026 22:12
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.69%. Comparing base (4482fe7) to head (a4cfb8b).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2071   +/-   ##
=======================================
  Coverage   84.69%   84.69%           
=======================================
  Files         118      118           
  Lines       14122    14122           
=======================================
  Hits        11960    11960           
  Misses       2162     2162           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@zimeg zimeg left a comment

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.

🗃️ @WilliamBergamin LGTM! Breaking ties on the autoincrement id is a clean fix that leaves existing databases untouched.

@mwbrooks mwbrooks left a comment

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.

✅ Thanks @WilliamBergamin! Breaking the tie on id means a reinstall in the same second hands back the new token, with no schema change for existing databases.

and
team_id = ?
order by installed_at desc
order by installed_at desc, id desc

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented oauth semver:patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants