classification
Title: sqlite3.Connection.iterdump() does not work with row_factory = sqlite3.Row
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: loewis, peter.otten, plemarre, python-dev, r.david.murray
Priority: normal Keywords: patch

Created on 2012-08-03 08:07 by plemarre, last changed 2013-01-10 16:35 by r.david.murray. This issue is now closed.

Files
File name Uploaded Description Edit
iterdump.diff peter.otten, 2012-08-06 20:44 review
Messages (8)
msg167296 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-08-03 08:09
Can you please elaborate? Structure your report as follows:

1. this is what I did
2. this is what happened
3. this is what should have happened instead.
msg167297 - (view) Author: Pierre Le Marre (plemarre) Date: 2012-08-03 08:27
I use Python 3.2.3 on GNU/Linux 64bits (openSUSE 12.2).
I have created an in-memory connection with the following code:

conn = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES, check_same_thread=False)
conn.row_factory = sqlite3.Row

Then I have filled the database, but when it comes to copy it via conn.iterdump(), it crashed with the following message:

File "/usr/lib64/python3.2/sqlite3/dump.py", line 30, in _iterdump
    for table_name, type, sql in sorted(schema_res.fetchall()):
TypeError: unorderable types: sqlite3.Row() < sqlite3.Row()

It seems that the error appears because of the use of "sorted()". In fact, if I don't change conn.row_factory or if I use a custom class _Row implementing __lt__ method (see below) this error does not appear.

class _Row(sqlite3.Row):
    def __lt__(self, x):
        return False
msg167543 - (view) Author: Pierre Le Marre (plemarre) Date: 2012-08-06 07:59
By the way, this issue does not appear with Python 3.2.2.
msg167579 - (view) Author: Peter Otten (peter.otten) * Date: 2012-08-06 20:44
Here's a minimal fix that modifies the sql in sqlite3.dump._iterdump() to sort the tables by name. It is then no longer necessary to sort the resultset in Python for the unit tests to pass.
msg170875 - (view) Author: Pierre Le Marre (plemarre) Date: 2012-09-21 09:52
Thanks for the patch. In which version will be your patch integrated?
msg179559 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-01-10 15:33
For the record, this is a regression introduced by the fix for issue 9750.  I plan to commit the fix shortly, thanks for the report and patch.
msg179566 - (view) Author: Roundup Robot (python-dev) Date: 2013-01-10 16:31
New changeset 2cdb599172ab by R David Murray in branch '3.2':
#15545: fix sqlite3.iterdump regression on unsortable row_factory objects.
http://hg.python.org/cpython/rev/2cdb599172ab

New changeset 6a85894c428f by R David Murray in branch '3.3':
merge #15545: fix sqlite3.iterdump regression on unsortable row_factory objects.
http://hg.python.org/cpython/rev/6a85894c428f

New changeset 7a62b5ee32ec by R David Murray in branch 'default':
merge #15545: fix sqlite3.iterdump regression on unsortable row_factory objects.
http://hg.python.org/cpython/rev/7a62b5ee32ec

New changeset bb4e4f0cec2e by R David Murray in branch '2.7':
#15545: sort iterdump via SQL instead of in python code
http://hg.python.org/cpython/rev/bb4e4f0cec2e
msg179568 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-01-10 16:35
Peter, I see you've made contributions before, but you don't show as having a contributor agreement on file according to the tracker.  Have you sent one in?  If not, would you, please?

Thanks again for the fix.
History
Date User Action Args
2013-01-10 16:35:59r.david.murraysetstatus: open -> closed
messages: + msg179568

components: + Library (Lib), - None
resolution: fixed
stage: commit review -> resolved
2013-01-10 16:31:33python-devsetnosy: + python-dev
messages: + msg179566
2013-01-10 15:33:51r.david.murraysetversions: + Python 2.7, Python 3.3, Python 3.4
nosy: + r.david.murray

messages: + msg179559

type: crash -> behavior
stage: commit review
2012-09-21 09:52:46plemarresetmessages: + msg170875
2012-08-06 20:44:04peter.ottensetfiles: + iterdump.diff

nosy: + peter.otten
messages: + msg167579

keywords: + patch
2012-08-06 07:59:43plemarresetmessages: + msg167543
2012-08-03 08:27:02plemarresetmessages: + msg167297
2012-08-03 08:09:32loewissetnosy: + loewis
messages: + msg167296
2012-08-03 08:07:56plemarrecreate