diff --git a/peewee.py b/peewee.py index 9c83383b8..ba651c31d 100644 --- a/peewee.py +++ b/peewee.py @@ -6237,8 +6237,10 @@ def _normalize_data(cls, data, kwargs): field = (key if isinstance(key, Field) else cls._meta.combined[key]) except KeyError: - raise ValueError('Unrecognized field name: "%s" in %s.' % - (key, data)) + if not isinstance(key, Node): + raise ValueError('Unrecognized field name: "%s" in %s.' + % (key, data)) + field = key normalized[field] = data[key] if kwargs: for key in kwargs: diff --git a/playhouse/postgres_ext.py b/playhouse/postgres_ext.py index b8134bbc7..a50510d0f 100644 --- a/playhouse/postgres_ext.py +++ b/playhouse/postgres_ext.py @@ -62,6 +62,9 @@ def __init__(self, node, parts): def clone(self): return type(self)(self.node, list(self.parts)) + def __hash__(self): + return hash((self.__class__.__name__, id(self))) + class _JsonLookupBase(_LookupNode): def __init__(self, node, parts, as_json=False): diff --git a/tests/postgres.py b/tests/postgres.py index b62605a82..3fef03e69 100644 --- a/tests/postgres.py +++ b/tests/postgres.py @@ -306,6 +306,18 @@ def test_index_expression(self): q = ArrayModel.select().where(ArrayModel.tags[last_tag] > 'd') self.assertEqual([a.id for a in q], [am_ids[1]]) + def test_hashable_objectslice(self): + ArrayModel.create(tags=[], ints=[[0, 1], [2, 3]]) + ArrayModel.create(tags=[], ints=[[4, 5], [6, 7]]) + n = (ArrayModel + .update({ArrayModel.ints[0][0]: ArrayModel.ints[0][0] + 1}) + .execute()) + self.assertEqual(n, 2) + + am1, am2 = ArrayModel.select().order_by(ArrayModel.id) + self.assertEqual(am1.ints, [[1, 1], [2, 3]]) + self.assertEqual(am2.ints, [[5, 5], [6, 7]]) + def test_array_get_set(self): am = self.create_sample() am_db = ArrayModel.get(ArrayModel.id == am.id)