Skip to content

Commit 08263f1

Browse files
committed
(Merge 3.3) Issue #20026: Fix the sqlite module to handle correctly invalid
isolation level (wrong type).
2 parents cf58fb5 + cb1f74e commit 08263f1

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/sqlite3/test/regression.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ def CheckConvertTimestampMicrosecondPadding(self):
330330
datetime.datetime(2012, 4, 4, 15, 6, 0, 123456),
331331
])
332332

333+
def CheckInvalidIsolationLevelType(self):
334+
# isolation level is a string, not an integer
335+
self.assertRaises(TypeError,
336+
sqlite.connect, ":memory:", isolation_level=123)
337+
333338

334339
def suite():
335340
regression_suite = unittest.makeSuite(RegressionTests, "Check")

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Core and Builtins
4444
Library
4545
-------
4646

47+
- Issue #20026: Fix the sqlite module to handle correctly invalid isolation
48+
level (wrong type).
49+
4750
- Issue #18829: csv.Dialect() now checks type for delimiter, escapechar and
4851
quotechar fields. Original patch by Vajrasky Kok.
4952

Modules/_sqlite/connection.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
128128
Py_INCREF(isolation_level);
129129
}
130130
self->isolation_level = NULL;
131-
pysqlite_connection_set_isolation_level(self, isolation_level);
131+
if (pysqlite_connection_set_isolation_level(self, isolation_level) < 0) {
132+
Py_DECREF(isolation_level);
133+
return -1;
134+
}
132135
Py_DECREF(isolation_level);
133136

134137
self->statement_cache = (pysqlite_Cache*)PyObject_CallFunction((PyObject*)&pysqlite_CacheType, "Oi", self, cached_statements);

0 commit comments

Comments
 (0)