Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions Lib/test/test_sqlite3/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ def test_sqlite_row_index(self):
with self.assertRaises(IndexError):
row[complex()] # index must be int or string

def test_delete_connection_row_factory(self):
# gh-149738: deleting row_factory should not segfault
del self.con.row_factory
with self.assertRaises(sqlite.OperationalError):
self.con.execute("test")
cur = self.con.cursor()
self.assertIsNone(cur.row_factory)

def test_sqlite_row_index_unicode(self):
row = self.con.execute("select 1 as \xff").fetchone()
self.assertEqual(row["\xff"], 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a segmentation fault in :mod:`sqlite3` when ``row_factory`` is deleted
and a query is executed afterward.
2 changes: 1 addition & 1 deletion Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory)
return NULL;
}

if (cursor && self->row_factory != Py_None) {
if (cursor && self->row_factory && self->row_factory != Py_None) {
Py_INCREF(self->row_factory);
Py_XSETREF(((pysqlite_Cursor *)cursor)->row_factory, self->row_factory);
}
Expand Down
Loading