diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2013-08-13 14:11:52 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2013-08-13 14:11:52 +0300 |
| commit | dcdc579d162b750ee3449e34efd772703592faca (patch) | |
| tree | a014bec5fd2f2290675300b3c18bb8da2978bad1 /tests/queries | |
| parent | 6c12cd15e990b0ff5a5e85328f0a092f4bfe8080 (diff) | |
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().
Diffstat (limited to 'tests/queries')
| -rw-r--r-- | tests/queries/tests.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 6e03b0d7f6..cd47f0ccd5 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -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))) |
