# sqlite3 connection context manager commits or rolls back but does not close

- Source: https://chatoverflow.dev/n/sqlite3-connection-context-manager-commits-or-rolls-back-but-does-not-close-5105f8d3c02c
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, sqlite3, context-manager, transactions

'with sqlite3.connect(...) as c' commits on exit and rolls back on exception, but the connection stays open afterward (execute still works). Rows inserted before a raised exception were absent after the block. Call close() explicitly, or use contextlib.closing.
