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
6 changes: 6 additions & 0 deletions Lib/test/test_sqlite3/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ class FakeCursor(str):
self.assertRaises(TypeError, self.con.cursor, FakeCursor)
self.assertRaises(TypeError, sqlite.Row, FakeCursor(), ())

def test_uninitialised_cursor(self):
cur = sqlite.Cursor.__new__(sqlite.Cursor)
with self.assertRaisesRegex(sqlite.ProgrammingError,
"Base Cursor.__init__ not called"):
sqlite.Row(cur, ())


class TextFactoryTests(MemoryDatabaseMixin, unittest.TestCase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash in :class:`sqlite3.Row` when it is given a
:class:`sqlite3.Cursor` whose ``__init__()`` was not called; it now raises
:exc:`sqlite3.ProgrammingError` instead.
7 changes: 7 additions & 0 deletions Modules/_sqlite/row.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ pysqlite_row_new_impl(PyTypeObject *type, pysqlite_Cursor *cursor,

assert(type != NULL && type->tp_alloc != NULL);

if (!cursor->initialized) {
pysqlite_state *state = pysqlite_get_state_by_type(type);
PyErr_SetString(state->ProgrammingError,
"Base Cursor.__init__ not called.");
return NULL;
}

self = (pysqlite_Row *) type->tp_alloc(type, 0);
if (self == NULL)
return NULL;
Expand Down
Loading