diff -r 00bfe5bd3553 Lib/sqlite3/test/transactions.py --- a/Lib/sqlite3/test/transactions.py Thu Nov 24 11:57:05 2016 -0800 +++ b/Lib/sqlite3/test/transactions.py Fri Nov 25 11:35:41 2016 +0200 @@ -148,6 +148,15 @@ with self.assertRaises(sqlite.InterfaceError): cur.fetchall() + def CheckManualTransaction(self): + """ + This checks that we can start a transaction manually by calling + "begin immediate". See issue #28518. + """ + self.cur1.execute("begin immediate") + with self.assertRaises(sqlite.OperationalError): + self.cur2.execute("create table test(x)") + class SpecialCommandTests(unittest.TestCase): def setUp(self): self.con = sqlite.connect(":memory:") diff -r 00bfe5bd3553 Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c Thu Nov 24 11:57:05 2016 -0800 +++ b/Modules/_sqlite/cursor.c Fri Nov 25 11:35:41 2016 +0200 @@ -564,6 +564,13 @@ goto error; } } else { + /* patch for issue 28518 */ + if (SQLITE_ERROR == rc && + strcmp("cannot start a transaction within a transaction", + sqlite3_errmsg(self->connection->db)) == 0) { + pysqlite_connection_rollback(self->connection, NULL); + continue; + } if (PyErr_Occurred()) { /* there was an error that occurred in a user-defined callback */ if (_enable_callback_tracebacks) {