Fixed #29643 -- Fixed crash when combining Q objects with __in lookups and lists.

Regression in fc6528b25a.
This commit is contained in:
Mariusz Felisiak 2018-08-08 08:51:20 +02:00 committed by GitHub
parent 3767c7ff39
commit 9fee229874
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -71,7 +71,10 @@ class Node:
)
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):
"""

View File

@ -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`).

View File

@ -23,10 +23,12 @@ class NodeTests(unittest.TestCase):
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):