Skip to content

Commit

Permalink
[2.1.x] Fixed #29643 -- Fixed crash when combining Q objects with __i…
Browse files Browse the repository at this point in the history
…n lookups and lists.

Regression in fc6528b.
Backport of 9fee229 from master
  • Loading branch information
felixxm committed Aug 8, 2018
1 parent d46bf11 commit 2bf766c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion django/utils/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def __eq__(self, other):
)

def __hash__(self):
return hash((self.__class__, self.connector, self.negated) + tuple(self.children))
return hash((self.__class__, self.connector, self.negated) + tuple([
tuple(child) if isinstance(child, list) else child
for child in self.children
]))

def add(self, data, conn_type, squash=True):
"""
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/2.1.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ Bugfixes
* Fixed a regression in Django 2.0 where using ``manage.py test --keepdb``
fails on PostgreSQL if the database exists and the user doesn't have
permission to create databases (:ticket:`29613`).

* Fixed a regression in Django 2.0 where combining ``Q`` objects with ``__in``
lookups and lists crashed (:ticket:`29643`).
2 changes: 2 additions & 0 deletions tests/utils_tests/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def test_hash(self):
node3 = Node(self.node1_children, negated=True)
node4 = Node(self.node1_children, connector='OTHER')
node5 = Node(self.node1_children)
node6 = Node([['a', 1], ['b', 2]])
self.assertNotEqual(hash(self.node1), hash(self.node2))
self.assertNotEqual(hash(self.node1), hash(node3))
self.assertNotEqual(hash(self.node1), hash(node4))
self.assertEqual(hash(self.node1), hash(node5))
self.assertEqual(hash(self.node1), hash(node6))
self.assertEqual(hash(self.node2), hash(Node()))

def test_len(self):
Expand Down

0 comments on commit 2bf766c

Please sign in to comment.