Repository navigation
fix(oauth): close sqlite3 connections in the installation and state stores - #2098
Conversation
…tores A sqlite3 Connection used as a context manager commits or rolls back but never closes, so every store call left its connection to garbage collection (a ResourceWarning on Python 3.13+). Wrap all twelve sites in contextlib.closing; every write already commits explicitly. 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 #2098 +/- ##
=======================================
Coverage 84.96% 84.96%
=======================================
Files 118 118
Lines 14285 14287 +2
=======================================
+ Hits 12137 12139 +2
Misses 2148 2148 ☔ View full report in Codecov by Harness. |
mwbrooks
left a comment
There was a problem hiding this comment.
✅ Thanks @WilliamBergamin, no more unclosed database warnings on 3.13 and the tests prove it.
|
|
||
|
|
||
| @contextmanager | ||
| def record_return_values(module: Any, name: str) -> Iterator[List[Any]]: |
There was a problem hiding this comment.
praise: Keeping each connection alive is the clever bit here, since without it garbage collection closes them and the test would pass on main too.
zimeg
left a comment
There was a problem hiding this comment.
🐍 @WilliamBergamin LGTM! Every write already commits on its own, so closing these connections is a tidy fix 🧹
Summary
This pull request closes the sqlite3 connections opened by
SQLite3InstallationStoreandSQLite3OAuthStateStore.sqlite3.Connectionas a context manager commits or rolls back, but it never closes the connection. So every store call left its connection for garbage collection, and on Python 3.13+ each one emitsResourceWarning: unclosed database.with ... as conn:sites now usecontextlib.closing,init()andcreate_tables()included. Every write already callsconn.commit()itself, and closing a connection discards an uncommitted transaction the same way the old rollback did.tests/helpers.pygainsrecord_return_values, which keeps each connection alive so the new tests can check that it was closed. Without it, garbage collection would close the connection and the tests would pass onmain.Testing
On Python 3.13+, run
python -W always::ResourceWarning -m pytest tests/slack_sdk/oauth/state_store/test_sqlite3.py.mainprintsunclosed databasewarnings and this branch prints none. The newtest_closes_every_connectiontests fail onmainand pass here.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