GeezerVison is showing github.com — Emit resource warning if sqlite3 fails to close the database · Issue #105539 · python/cpython
Emit resource warning if sqlite3 fails to close the database #105539DescriptionSee #103837 (comment) and #103837 (comment):
EAA:
I still think we should consider changing the underlying API so we can emit a resource warning if close failed.
VS:
IMO sqlite3 should be modified to emit a ResourceWarning.
Currently, no ResourceWarning is emitted when a connection is not closed explicitly:
Linked PRs
Activityvstinner commented on Aug 16, 2023 What is the consequences if a database is not closed explicitly and fails to be closed at Python exit? Is there a risk of losing data? erlend-aasland commented on Aug 16, 2023 ContributorAuthor More actions
What is the consequences if a database is not closed explicitly and fails to be closed at Python exit? Is there a risk of losing data?
If sqlite3_close() or sqlite3_close_v2() fails, there is of course a risk of losing data. However, we do a pretty good job at cleaning up the connection and its debris (cursors, statements, registered callbacks, etc.), so that risk is almost non-existent :) vstinner commented on Aug 16, 2023 By "fail to be closed", I was thinking about a database connection involved in a reference cycle which is impossible to break, and so close() is never called and the object is never destroyed. erlend-aasland commented on Aug 17, 2023 ContributorAuthor More actions
By "fail to be closed", I was thinking about a database connection involved in a reference cycle which is impossible to break, and so close() is never called and the object is never destroyed.
If the connection object is never destroyed (dealloc or finalize are never called), there is no way to detect that in the extension module that I know about. The proposed change involves both the finalizer and the dealloc callbacks, so I'm relying on them actually being called at some point. added 2 commits that reference this issue on Aug 17, 2023gh-105539: Explict resource management for connection objects in sqli… gh-105539: Emit ResourceWarning if sqlite3 database is not closed exp… vstinner commented on Aug 22, 2023 Congrats :-) IMO it's a nice enhancement. Reacted by Erlend E. Aasland erlend-aasland commented on Aug 22, 2023 ContributorAuthor More actions Thanks for bringing the idea up in the first place, Victor! :) erlend-aasland commented on Aug 23, 2023 ContributorAuthor More actions Apparently, I did not cover all cases in #108017; the following now emit resource warnings:
./python.exe -m test -R : test_sqlite3 -m ClosedCurTests
added 2 commits that reference this issue on Aug 23, 2023gh-105539: Fix ResourceWarning from unclosed SQLite connections in te…
MetadataMetadataStatusShow more project fields
DevelopmentNo branches or pull requestsIssue actions
|