mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-105539: Emit ResourceWarning if sqlite3 database is not closed explicitly (#108015)
This commit is contained in:
parent
86617518c4
commit
1a1bfc2891
5 changed files with 30 additions and 0 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue