Skip to content

Fix unclosed sqlite3 connections in updates.py#270

Merged
cmutel merged 1 commit into
mainfrom
fix/unclosed-sqlite-connections
May 14, 2026
Merged

Fix unclosed sqlite3 connections in updates.py#270
cmutel merged 1 commit into
mainfrom
fix/unclosed-sqlite-connections

Conversation

@cmutel
Copy link
Copy Markdown
Member

@cmutel cmutel commented May 14, 2026

Closes #269

Summary

  • set_initial_updates() ran PRAGMA table_info(activitydataset) via a fresh sqlite3.connect(), even though the Peewee-managed connection was already open — replaced with sqlite3_lci_db.execute_sql(SQL), eliminating the extra connection entirely
  • schema_change_20_compound_keys() opened a connection with with sqlite3.connect(...) as conn — replaced with contextlib.closing(sqlite3.connect(...)) so the connection is explicitly closed on exit

Root cause

Python's with sqlite3.connect(...) as conn manages the transaction context but does not close the connection when the block exits. Connections stayed open until GC'd, triggering ResourceWarning: unclosed database across many tests.

Test plan

  • CI passes
  • No ResourceWarning: unclosed database in test output

Python's `with sqlite3.connect() as conn` manages transactions but does
NOT close the connection on exit — it stays open until GC'd, triggering
ResourceWarning. Fix set_initial_updates to reuse the existing Peewee
connection via execute_sql(), and fix schema_change_20_compound_keys
to use contextlib.closing() so the connection is explicitly closed.
@cmutel cmutel merged commit 646849c into main May 14, 2026
9 checks passed
cmutel added a commit that referenced this pull request May 14, 2026
@cmutel cmutel mentioned this pull request May 14, 2026
2 tasks
cmutel added a commit that referenced this pull request May 14, 2026
* Release 4.7

Add changelog entry for 4.7 release.

* Add #268 to 4.7 changelog

* Add #270 to 4.7 changelog
@cmutel cmutel self-assigned this May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResourceWarning: unclosed database connections in updates.py

1 participant