Skip to content

Commit 0e6cb2e

Browse files
palavivberkerpeksag
authored andcommitted
bpo-26187: Test that set_trace_callback() is not called multiple times (GH-461)
conn.set_trace_callback() shouldn't be called multiple times when the schema is changing. This has indirectly been fixed by using sqlite3_prepare_v2() in bpo-9303.
1 parent 2abfdf5 commit 0e6cb2e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Lib/sqlite3/test/hooks.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import unittest
2525
import sqlite3 as sqlite
2626

27+
from test.support import TESTFN, unlink
28+
2729
class CollationTests(unittest.TestCase):
2830
def CheckCreateCollationNotString(self):
2931
con = sqlite.connect(":memory:")
@@ -248,6 +250,24 @@ def trace(statement):
248250
"Unicode data %s garbled in trace callback: %s"
249251
% (ascii(unicode_value), ', '.join(map(ascii, traced_statements))))
250252

253+
@unittest.skipIf(sqlite.sqlite_version_info < (3, 3, 9), "sqlite3_prepare_v2 is not available")
254+
def CheckTraceCallbackContent(self):
255+
# set_trace_callback() shouldn't produce duplicate content (bpo-26187)
256+
traced_statements = []
257+
def trace(statement):
258+
traced_statements.append(statement)
259+
260+
queries = ["create table foo(x)",
261+
"insert into foo(x) values(1)"]
262+
self.addCleanup(unlink, TESTFN)
263+
con1 = sqlite.connect(TESTFN, isolation_level=None)
264+
con2 = sqlite.connect(TESTFN)
265+
con1.set_trace_callback(trace)
266+
cur = con1.cursor()
267+
cur.execute(queries[0])
268+
con2.execute("create table bar(x)")
269+
cur.execute(queries[1])
270+
self.assertEqual(traced_statements, queries)
251271

252272

253273
def suite():

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ Extension Modules
307307
Library
308308
-------
309309

310+
- bpo-26187: Test that sqlite3 trace callback is not called multiple
311+
times when schema is changing. Indirectly fixed by switching to
312+
use sqlite3_prepare_v2() in bpo-9303. Patch by Aviv Palivoda.
313+
310314
- bpo-29998: Pickling and copying ImportError now preserves name and path
311315
attributes.
312316

0 commit comments

Comments
 (0)