Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
gh-156100: Fix a crash when deleting sqlite3 Connection.autocommit
The setter passed the deleted value to autocommit_converter(), which
dereferences it.
  • Loading branch information
serhiy-storchaka committed Aug 20, 2026
commit 2cf1c76a7076f909f463ffc5cc5b6c59ba6e3be6
7 changes: 7 additions & 0 deletions Lib/test/test_sqlite3/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ def test_autocommit_setget_invalid(self):
with self.assertRaisesRegex(ValueError, msg):
sqlite.connect(":memory:", autocommit=mode)

def test_autocommit_delete(self):
with memory_database() as cx:
with self.assertRaisesRegex(AttributeError,
"cannot delete autocommit attribute"):
del cx.autocommit
self.assertEqual(cx.autocommit, sqlite.LEGACY_TRANSACTION_CONTROL)

def test_autocommit_disabled(self):
expected = [
"SELECT 1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash when deleting the :attr:`~sqlite3.Connection.autocommit`
attribute of :class:`sqlite3.Connection`.
It now raises :exc:`AttributeError`.
5 changes: 5 additions & 0 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2621,6 +2621,11 @@ static int
set_autocommit(PyObject *op, PyObject *val, void *Py_UNUSED(closure))
{
pysqlite_Connection *self = _pysqlite_Connection_CAST(op);
if (val == NULL) {
PyErr_SetString(PyExc_AttributeError,
"cannot delete autocommit attribute");
return -1;
}
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return -1;
}
Expand Down
Loading