-
-
Notifications
You must be signed in to change notification settings - Fork 799
Fixed hundreds of database connection closing warnings #2615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
From 409 warnings down to 52 warnings. Claude Code says: Fixed connection leaks in: 1. datasette/utils/sqlite.py - _sqlite_version() now closes connection 2. datasette/cli.py - --create flag now closes connection 3. datasette/app.py - _versions() now closes connection 4. datasette/utils/__init__.py - detect_json1() now closes connection when created internally 5. tests/conftest.py - pytest_report_header() now closes connection 6. tests/utils.py - has_load_extension() now closes connection 7. tests/fixtures.py - app_client_no_files and CLI fixtures now close connections 8. tests/test_api_write.py - ds_write fixture closes both connections 9. tests/test_cli.py - Multiple test functions now close connections 10. tests/test_config_dir.py - config_dir and config_dir_client fixtures now close connections 11. tests/test_crossdb.py - Loop connections now closed 12. tests/test_internals_database.py - Test setup connections now closed 13. tests/test_plugins.py - view_names_client fixture and test now close connections 14. tests/test_utils.py - Multiple test functions now close connections Refs #2614
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2615 +/- ##
==========================================
- Coverage 90.20% 90.05% -0.16%
==========================================
Files 51 51
Lines 7497 7571 +74
==========================================
+ Hits 6763 6818 +55
- Misses 734 753 +19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Got Claude Code to fix the remaining warnings! The terminal to HTML output is a huge 4MB, recorded here: https://static.simonwillison.net/static/2025/big-terminal.html The summary:
|
|
Gonna have to review this very carefully, there's a lot of deep clever stuff going on. |
| def detect_json1(conn=None): | ||
| close_conn = False | ||
| if conn is None: | ||
| conn = sqlite3.connect(":memory:") | ||
| close_conn = True | ||
| try: | ||
| conn.execute("SELECT json('{}')") | ||
| return True | ||
| except Exception: | ||
| return False | ||
| finally: | ||
| if close_conn: | ||
| conn.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
| conn = sqlite3.connect(":memory:") | ||
| try: | ||
| return tuple( | ||
| map( | ||
| int, | ||
| conn.execute("select sqlite_version()").fetchone()[0].split("."), | ||
| ) | ||
| ) | ||
| ) | ||
| finally: | ||
| conn.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good pattern here too.
From 409 warnings down to 52 warnings.
Claude Code says: https://gistpreview.github.io/?69d2ce58f09fdd8463e384cc1ebee4cf
Fixed connection leaks in:
Refs:
📚 Documentation preview 📚: https://datasette--2615.org.readthedocs.build/en/2615/