8000 gh-108083: Don't ignore exceptions in sqlite3.Connection.__init__() and .close() by erlend-aasland · Pull Request #108084 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-108083: Don't ignore exceptions in sqlite3.Connection.__init__() and .close() #108084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review: let connection_close() return a value and the caller …
…decide what to do
  • Loading branch information
erlend-aasland committed Aug 17, 2023
commit 7b3d032abc2fd619382b0e0e6714eafb93777dbe
24 changes: 16 additions & 8 deletions 8000 Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
static void free_callback_context(callback_context *ctx);
static void set_callback_context(callback_context **ctx_pp,
callback_context *ctx);
static void connection_close(pysqlite_Connection *self);
static int connection_close(pysqlite_Connection *self);
PyObject *_pysqlite_query_execute(pysqlite_Cursor *, int, PyObject *, PyObject *);

static PyObject *
Expand Down Expand Up @@ -249,7 +249,9 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
if (self->initialized) {
PyTypeObject *tp = Py_TYPE(self);
tp->tp_clear((PyObject *)self);
connection_close(self);
if (connection_close(self) < 0) {
return -1;
}
self->initialized = 0;
}

Expand Down Expand Up @@ -439,7 +441,7 @@ remove_callbacks(sqlite3 *db)
(void)sqlite3_set_authorizer(db, NULL, NULL);
}

static void
static int
connection_close(pysqlite_Connection *self)
{
if (self->db) {
Expand All @@ -452,7 +454,7 @@ connection_close(pysqlite_Connection *self)
remove_callbacks(self->db);
}
if (connection_exec_stmt(self, "ROLLBACK") < 0) {
PyErr_WriteUnraisable((PyObject *)self);
return -1;
}
}

Expand All @@ -466,17 +468,21 @@ connection_close(pysqlite_Connection *self)
assert(rc == SQLITE_OK), (void)rc;
Py_END_ALLOW_THREADS
}
return 0;
}

static void
connection_dealloc(pysqlite_Connection *self)
connection_dealloc(PyObject *self)
{
pysqlite_Connection *con = (pysqlite_Connection *)self;
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
tp->tp_clear((PyObject *)self);
tp->tp_clear(self);

/* Clean up if user has not called .close() explicitly. */
connection_close(self);
if (connection_close(con) < 0) {
PyErr_WriteUnraisable((PyObject *)self);
}

tp->tp_free(self);
Py_DECREF(tp);
Expand Down Expand Up @@ -625,7 +631,9 @@ pysqlite_connection_close_impl(pysqlite_Connection *self)

pysqlite_close_all_blobs(self);
Py_CLEAR(self->statement_cache);
connection_close(self);
if (connection_close(self) < 0) {
return NULL;
}

Py_RETURN_NONE;
}
Expand Down
0