tonghuaroot · GitHub

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

Read the original on github.com ↗