gh-105539: Emit ResourceWarning if sqlite3 database is not closed explicitly (#108015)

This commit is contained in:
Erlend E. Aasland 2023-08-22 13:10:29 +02:00 committed by GitHub
parent 86617518c4
commit 1a1bfc2891
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 0 deletions

View file

@ -493,6 +493,14 @@ connection_finalize(PyObject *self)
}
/* Clean up if user has not called .close() explicitly. */
if (con->db) {
if (PyErr_ResourceWarning(self, 1, "unclosed database in %R", self)) {
/* Spurious errors can appear at shutdown */
if (PyErr_ExceptionMatches(PyExc_Warning)) {
PyErr_WriteUnraisable(self);
}
}
}
if (connection_close(con) < 0) {
if (teardown) {
PyErr_Clear();