10000 bpo-41662: Fix bugs in binding parameters in sqlite3 by serhiy-storchaka · Pull Request #21998 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-41662: Fix bugs in binding parameters in sqlite3 #21998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add tests.
  • Loading branch information
serhiy-storchaka committed Aug 30, 2020
commit a499bd59dc9fb9b6b589a547695793f141790e3e
14 changes: 13 additions & 1 deletion Lib/sqlite3/test/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def CheckExecuteParamList(self):
self.assertEqual(row[0], "foo")

def CheckExecuteParamSequence(self):
class L(object):
class L:
def __len__(self):
return 1
def __getitem__(self, x):
Expand All @@ -288,6 +288,18 @@ def __getitem__(self, x):
row = self.cu.fetchone()
self.assertEqual(row[0], "foo")

def CheckExecuteParamSequenceBadLen(self):
# Issue41662: Error in __len__() was overridden with ProgrammingError.
class L:
def __len__(self):
1/0
def __getitem__(slf, x):
raise AssertionError

self.cu.execute("insert into test(name) values ('foo')")
with self.assertRaises(ZeroDivisionError):
self.cu.execute("select name from test where name=?", L())

def CheckExecuteDictMapping(self):
self.cu.execute("insert into test(name) values ('foo')")
self.cu.execute("select name from test where name=:name", {"name": "foo"})
Expand Down
13 changes: 13 additions & 0 deletions Lib/sqlite3/test/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ def CheckTypeMapUsage(self):
con.execute("insert into foo(bar) values (5)")
con.execute(SELECT)

def CheckBindMutatingList(self):
# Issue41662: Crash when mutate a list of parameters during iteration.
class X:
def __conform__(self, protocol):
parameters.clear()
return "..."
parameters = [X(), 0]
con = sqlite.connect(":memory:",detect_types=sqlite.PARSE_DECLTYPES)
con.execute("create table foo(bar X, baz integer)")
# Should not crash
with self.assertRaises(IndexError):
con.execute("insert into foo(bar, baz) values (?, ?)", parameters)

def CheckErrorMsgDecodeError(self):
# When porting the module to Python 3.0, the error message about
# decoding errors disappeared. This verifies they're back again.
Expand Down
0