Repository navigation
fix(oauth): return the latest sqlite3 installation when saves share a second - #2071
WilliamBergamin wants to merge 1 commit into
Conversation
… 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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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. |
zimeg
left a comment
There was a problem hiding this comment.
🗃️ @WilliamBergamin LGTM! Breaking ties on the autoincrement id is a clean fix that leaves existing databases untouched.
mwbrooks
left a comment
There was a problem hiding this comment.
✅ 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 |
There was a problem hiding this comment.
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.
Summary
This pull request makes
SQLite3InstallationStorereturn the latest installation when two saves land in the same second.save()leavesinstalled_atto the column defaultcurrent_timestamp, which has 1 s resolution. Saves in the same second tie onorder by installed_at desc, and SQLite picks a tied row in no defined order. Locally, the no-userfind_installationand the latest-bot-token merge returned the older row, so a reinstall or token rotation could hand back a stale token.installed_at desc, id desc.idis the autoincrement key, so the newest insert wins a tie. There is no schema or data change.Installation.installed_atinstead 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 originalinstalled_at.Testing
test_find_returns_latest_save_within_the_same_secondsaves an old and a new installation plus a user-only one, then forces all rows to the sameinstalled_at. It fails onmain(the no-user lookup returnsxoxp-old) and passes here. SQLite doesn't define the order of tied rows, so another SQLite build could pass it onmainby chance; it stays in as a regression guard.Category
/docs(Documents)/tutorial(PythOnBoardingBot tutorial)tests/integration_tests(Automated tests for this library)Requirements
python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.shafter making the changes.🤖 Generated with Claude Code