diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2018-07-14 12:03:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-14 12:03:22 +0200 |
| commit | dd3b4707198f17557fdd9fe7a6fd9025b23dcaf3 (patch) | |
| tree | dd7066beda88403e364eb9dab24ece335092b0d4 /tests/annotations | |
| parent | 312eb5cb11d09c0c41b2740e2e9aef838d60c8b5 (diff) | |
Fixed #29542 -- Fixed invalid SQL if a Subquery from the HAVING clause is used in the GROUP BY clause.
Thanks Tim Graham for the review.
Diffstat (limited to 'tests/annotations')
| -rw-r--r-- | tests/annotations/tests.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index c1073d6f41..021f59d2d7 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -4,7 +4,7 @@ from decimal import Decimal from django.core.exceptions import FieldDoesNotExist, FieldError from django.db.models import ( BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func, - IntegerField, NullBooleanField, Q, Sum, Value, + IntegerField, NullBooleanField, OuterRef, Q, Subquery, Sum, Value, ) from django.db.models.expressions import RawSQL from django.db.models.functions import Length, Lower @@ -585,3 +585,16 @@ class NonAggregateAnnotationTestCase(TestCase): qs, [{'jacob_name': 'Jacob Kaplan-Moss', 'james_name': 'James Bennett'}], ) + + @skipUnlessDBFeature('supports_subqueries_in_group_by') + def test_annotation_filter_with_subquery(self): + long_books_qs = Book.objects.filter( + publisher=OuterRef('pk'), + pages__gt=400, + ).values('publisher').annotate(count=Count('pk')).values('count') + publisher_books_qs = Publisher.objects.annotate( + total_books=Count('book'), + ).filter( + total_books=Subquery(long_books_qs, output_field=IntegerField()), + ).values('name') + self.assertCountEqual(publisher_books_qs, [{'name': 'Sams'}, {'name': 'Morgan Kaufmann'}]) |
