diff options
author | Erlend E. Aasland <erlend@python.org> | 2024-04-25 08:33:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-25 08:33:35 (GMT) |
commit | 7a843e8390f284fb6aa7c6fdebf88052a5b0be46 (patch) | |
tree | 464f7ab4688e1b8d4e88c18959c65290098e2efd /Lib/test | |
parent | fc1732ce3f26af5d082adac03ee73ef4814a5feb (diff) | |
download | cpython-7a843e8390f284fb6aa7c6fdebf88052a5b0be46.zip cpython-7a843e8390f284fb6aa7c6fdebf88052a5b0be46.tar.gz cpython-7a843e8390f284fb6aa7c6fdebf88052a5b0be46.tar.bz2 |
[3.12] gh-118221: Always use the default row factory in sqlite3.iterdump() (#118223) (#118270)
sqlite3.iterdump() depends on the row factory returning resulting rows
as tuples; it will fail with custom row factories like for example a
dict factory.
With this commit, we explicitly reset the row factory of the cursor used
by iterdump(), so we always get predictable results. This does not
affect the row factory of the parent connection.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_sqlite3/test_dump.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_sqlite3/test_dump.py b/Lib/test/test_sqlite3/test_dump.py index c3ed3ae..1dcce87 100644 --- a/Lib/test/test_sqlite3/test_dump.py +++ b/Lib/test/test_sqlite3/test_dump.py @@ -117,6 +117,21 @@ class DumpTests(unittest.TestCase): got = list(self.cx.iterdump()) self.assertEqual(expected, got) + def test_dump_custom_row_factory(self): + # gh-118221: iterdump should be able to cope with custom row factories. + def dict_factory(cu, row): + fields = [col[0] for col in cu.description] + return dict(zip(fields, row)) + + self.cx.row_factory = dict_factory + CREATE_TABLE = "CREATE TABLE test(t);" + expected = ["BEGIN TRANSACTION;", CREATE_TABLE, "COMMIT;"] + + self.cu.execute(CREATE_TABLE) + actual = list(self.cx.iterdump()) + self.assertEqual(expected, actual) + self.assertEqual(self.cx.row_factory, dict_factory) + def test_dump_virtual_tables(self): # gh-64662 expected = [ |