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

Regression in fc6528b25a.
This commit is contained in:
aspalding 2018-10-16 10:02:52 -05:00 committed by Tim Graham
parent 217f82d713
commit dc5e75d419
3 changed files with 9 additions and 6 deletions

View File

@ -5,6 +5,8 @@ ORM.
import copy import copy
from django.utils.hashable import make_hashable
class Node: class Node:
""" """
@ -71,10 +73,7 @@ class Node:
) )
def __hash__(self): def __hash__(self):
return hash((self.__class__, self.connector, self.negated, *[ return hash((self.__class__, self.connector, self.negated, *make_hashable(self.children)))
tuple(child) if isinstance(child, list) else child
for child in self.children
]))
def add(self, data, conn_type, squash=True): def add(self, data, conn_type, squash=True):
""" """

View File

@ -4,9 +4,10 @@ Django 2.1.3 release notes
*Expected November 1, 2018* *Expected November 1, 2018*
Django 2.1.3 fixes several bugs in 2.1.2 Django 2.1.3 fixes several bugs in 2.1.2.
Bugfixes Bugfixes
======== ========
* ... * Fixed a regression in Django 2.0 where combining ``Q`` objects with ``__in``
lookups and lists crashed (:ticket:`29838`).

View File

@ -24,12 +24,15 @@ class NodeTests(unittest.TestCase):
node4 = Node(self.node1_children, connector='OTHER') node4 = Node(self.node1_children, connector='OTHER')
node5 = Node(self.node1_children) node5 = Node(self.node1_children)
node6 = Node([['a', 1], ['b', 2]]) node6 = Node([['a', 1], ['b', 2]])
node7 = Node([('a', [1, 2])])
node8 = Node([('a', (1, 2))])
self.assertNotEqual(hash(self.node1), hash(self.node2)) self.assertNotEqual(hash(self.node1), hash(self.node2))
self.assertNotEqual(hash(self.node1), hash(node3)) self.assertNotEqual(hash(self.node1), hash(node3))
self.assertNotEqual(hash(self.node1), hash(node4)) self.assertNotEqual(hash(self.node1), hash(node4))
self.assertEqual(hash(self.node1), hash(node5)) self.assertEqual(hash(self.node1), hash(node5))
self.assertEqual(hash(self.node1), hash(node6)) self.assertEqual(hash(self.node1), hash(node6))
self.assertEqual(hash(self.node2), hash(Node())) self.assertEqual(hash(self.node2), hash(Node()))
self.assertEqual(hash(node7), hash(node8))
def test_len(self): def test_len(self):
self.assertEqual(len(self.node1), 2) self.assertEqual(len(self.node1), 2)