diff options
author | Erlend E. Aasland <erlend@python.org> | 2023-08-22 11:10:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-22 11:10:29 (GMT) |
commit | 1a1bfc28912a39b500c578e9f10a8a222638d411 (patch) | |
tree | 72f4cfae72eaafab1c28cc8a4c258667b2eaa48e /Modules/_sqlite | |
parent | 86617518c4ac824e2b6dc20691ba5a08df04f285 (diff) | |
download | cpython-1a1bfc28912a39b500c578e9f10a8a222638d411.zip cpython-1a1bfc28912a39b500c578e9f10a8a222638d411.tar.gz cpython-1a1bfc28912a39b500c578e9f10a8a222638d411.tar.bz2 |
gh-105539: Emit ResourceWarning if sqlite3 database is not closed explicitly (#108015)
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r-- | Modules/_sqlite/connection.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 282855f..e133977 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -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(); |