Skip to content

sqlite3.Row.__hash__ raises SystemError instead of TypeError for an unhashable value #153695

Description

@tonghuaroot

Bug description

sqlite3.Row.__hash__ calls PyObject_Hash on the row's description and data
without checking the -1 error return, so hashing a row that holds an
unhashable value raises SystemError instead of TypeError:

import sqlite3
sqlite3.register_converter("LST", lambda b: [1, 2, 3])
con = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)
con.row_factory = sqlite3.Row
con.execute("create table t(x LST)")
con.execute("insert into t values (?)", (b"x",))
row = con.execute("select x from t").fetchone()
hash(row)
# SystemError: <built-in function hash> returned a result with an exception set

Expected: TypeError: unhashable type: 'list'.

CPython versions tested on

3.14, 3.15, 3.16

Operating systems tested on

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions