Skip to content
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

sqlite3.Connection.iterdump() does not work with row_factory = sqlite3.Row #59750

Closed
plemarre mannequin opened this issue Aug 3, 2012 · 8 comments
Closed

sqlite3.Connection.iterdump() does not work with row_factory = sqlite3.Row #59750

plemarre mannequin opened this issue Aug 3, 2012 · 8 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@plemarre
Copy link
Mannequin

plemarre mannequin commented Aug 3, 2012

BPO 15545
Nosy @loewis, @bitdancer
Files
  • iterdump.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2013-01-10.16:35:59.047>
    created_at = <Date 2012-08-03.08:07:56.234>
    labels = ['type-bug', 'library']
    title = 'sqlite3.Connection.iterdump() does not work with row_factory = sqlite3.Row'
    updated_at = <Date 2013-01-10.16:35:58.907>
    user = 'https://bugs.python.org/plemarre'

    bugs.python.org fields:

    activity = <Date 2013-01-10.16:35:58.907>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-01-10.16:35:59.047>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2012-08-03.08:07:56.234>
    creator = 'plemarre'
    dependencies = []
    files = ['26710']
    hgrepos = []
    issue_num = 15545
    keywords = ['patch']
    message_count = 8.0
    messages = ['167296', '167297', '167543', '167579', '170875', '179559', '179566', '179568']
    nosy_count = 5.0
    nosy_names = ['loewis', 'peter.otten', 'r.david.murray', 'python-dev', 'plemarre']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue15545'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

    @plemarre plemarre mannequin added the type-crash A hard crash of the interpreter, possibly with a core dump label Aug 3, 2012
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Aug 3, 2012

    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.

    @plemarre
    Copy link
    Mannequin Author

    plemarre mannequin commented Aug 3, 2012

    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

    @plemarre
    Copy link
    Mannequin Author

    plemarre mannequin commented Aug 6, 2012

    By the way, this issue does not appear with Python 3.2.2.

    @peterotten
    Copy link
    Mannequin

    peterotten mannequin commented Aug 6, 2012

    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.

    @plemarre
    Copy link
    Mannequin Author

    plemarre mannequin commented Sep 21, 2012

    Thanks for the patch. In which version will be your patch integrated?

    @bitdancer
    Copy link
    Member

    For the record, this is a regression introduced by the fix for bpo-9750. I plan to commit the fix shortly, thanks for the report and patch.

    @bitdancer bitdancer added type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Jan 10, 2013
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 10, 2013

    New changeset 2cdb599172ab by R David Murray in branch '3.2':
    bpo-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 bpo-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 bpo-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':
    bpo-15545: sort iterdump via SQL instead of in python code
    http://hg.python.org/cpython/rev/bb4e4f0cec2e

    @bitdancer
    Copy link
    Member

    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.

    @bitdancer bitdancer added the stdlib Python modules in the Lib dir label Jan 10, 2013
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant