self.assertEqual(hash(row_1), hash(row_2))
+ def test_sqlite_row_hash_unhashable(self):
+ # An unhashable value must raise TypeError, not SystemError.
+ sqlite.register_converter("LST", lambda b: [1, 2, 3])
+ self.addCleanup(sqlite.converters.pop, "LST", None)
+ with memory_database(detect_types=sqlite.PARSE_DECLTYPES) as con:
+ con.row_factory = sqlite.Row
+ con.execute("create table t(x LST)")
+ con.execute("insert into t values(?)", (b"x",))
+ row = con.execute("select x from t").fetchone()
+ self.assertRaisesRegex(TypeError, "unhashable", hash, row)
+
def test_sqlite_row_as_sequence(self):
# Checks if the row object can act like a sequence.
row = self.con.execute("select 1 as a, 2 as b").fetchone()
pysqlite_row_hash(PyObject *op)
{
pysqlite_Row *self = _pysqlite_Row_CAST(op);
- return PyObject_Hash(self->description) ^ PyObject_Hash(self->data);
+ Py_hash_t hash_description = PyObject_Hash(self->description);
+ if (hash_description == -1) {
+ return -1;
+ }
+ Py_hash_t hash_data = PyObject_Hash(self->data);
+ if (hash_data == -1) {
+ return -1;
+ }
+ return hash_description ^ hash_data;
}
static PyObject *