diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-09-17 10:35:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-17 10:35:44 +0300 |
commit | 0b419b791077414bbc011a412698ebb362b63761 (patch) | |
tree | ee14bf8c868781a6d75c080acbaf110c94ae6270 /Lib/sqlite3/test/dbapi.py | |
parent | dcfaa520c4638a67052a4ff4a2a820be68750ad7 (diff) | |
download | cpython-0b419b791077414bbc011a412698ebb362b63761.tar.gz cpython-0b419b791077414bbc011a412698ebb362b63761.zip |
bpo-41662: Fix bugs in binding parameters in sqlite3 (GH-21998)
* When the parameters argument is a list, correctly handle the case
of changing it during iteration.
* When the parameters argument is a custom sequence, no longer
override an exception raised in ``__len__()``.
Diffstat (limited to 'Lib/sqlite3/test/dbapi.py')
-rw-r--r-- | Lib/sqlite3/test/dbapi.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/sqlite3/test/dbapi.py b/Lib/sqlite3/test/dbapi.py index a8dfeb9b2d6..7867bf361e5 100644 --- a/Lib/sqlite3/test/dbapi.py +++ b/Lib/sqlite3/test/dbapi.py @@ -270,7 +270,7 @@ class CursorTests(unittest.TestCase): self.assertEqual(row[0], "foo") def CheckExecuteParamSequence(self): - class L(object): + class L: def __len__(self): return 1 def __getitem__(self, x): @@ -282,6 +282,18 @@ class CursorTests(unittest.TestCase): 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"}) |