mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #20874 -- bump_prefix() in nested subqueries
Also made some cleanup to build_filter() code by introducing submethods solve_lookup_type() and prepare_lookup_value().
This commit is contained in:
@@ -27,7 +27,6 @@ from .models import (
|
||||
BaseA, FK1, Identifier, Program, Channel, Page, Paragraph, Chapter, Book,
|
||||
MyObject, Order, OrderItem)
|
||||
|
||||
|
||||
class BaseQuerysetTest(TestCase):
|
||||
def assertValueQuerysetEqual(self, qs, values):
|
||||
return self.assertQuerysetEqual(qs, values, transform=lambda x: x)
|
||||
@@ -84,6 +83,19 @@ class Queries1Tests(BaseQuerysetTest):
|
||||
Cover.objects.create(title="first", item=i4)
|
||||
Cover.objects.create(title="second", item=self.i2)
|
||||
|
||||
def test_subquery_condition(self):
|
||||
qs1 = Tag.objects.filter(pk__lte=0)
|
||||
qs2 = Tag.objects.filter(parent__in=qs1)
|
||||
qs3 = Tag.objects.filter(parent__in=qs2)
|
||||
self.assertEqual(qs3.query.subq_aliases, set(['T', 'U', 'V']))
|
||||
self.assertIn('V0', str(qs3.query))
|
||||
qs4 = qs3.filter(parent__in=qs1)
|
||||
self.assertEqual(qs4.query.subq_aliases, set(['T', 'U', 'V']))
|
||||
# It is possible to reuse U for the second subquery, no need to use W.
|
||||
self.assertNotIn('W0', str(qs4.query))
|
||||
# So, 'U0."id"' is referenced twice.
|
||||
self.assertTrue(str(qs4.query).count('U0."id"'), 2)
|
||||
|
||||
def test_ticket1050(self):
|
||||
self.assertQuerysetEqual(
|
||||
Item.objects.filter(tags__isnull=True),
|
||||
@@ -810,7 +822,7 @@ class Queries1Tests(BaseQuerysetTest):
|
||||
# Make sure bump_prefix() (an internal Query method) doesn't (re-)break. It's
|
||||
# sufficient that this query runs without error.
|
||||
qs = Tag.objects.values_list('id', flat=True).order_by('id')
|
||||
qs.query.bump_prefix()
|
||||
qs.query.bump_prefix(qs.query)
|
||||
first = qs[0]
|
||||
self.assertEqual(list(qs), list(range(first, first+5)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user