summaryrefslogtreecommitdiff
path: root/tests/annotations/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/annotations/tests.py')
-rw-r--r--tests/annotations/tests.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
index f7f8474329..4fc7e6f047 100644
--- a/tests/annotations/tests.py
+++ b/tests/annotations/tests.py
@@ -6,6 +6,7 @@ from django.db.models import (
BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func,
IntegerField, NullBooleanField, Q, Sum, Value,
)
+from django.db.models.expressions import RawSQL
from django.db.models.functions import Length, Lower
from django.test import TestCase, skipUnlessDBFeature
@@ -322,6 +323,17 @@ class NonAggregateAnnotationTestCase(TestCase):
for publisher in publishers.filter(pk=self.p1.pk):
self.assertEqual(publisher['book__rating'], publisher['total'])
+ @skipUnlessDBFeature('allows_group_by_pk')
+ def test_rawsql_group_by_collapse(self):
+ raw = RawSQL('SELECT MIN(id) FROM annotations_book', [])
+ qs = Author.objects.values('id').annotate(
+ min_book_id=raw,
+ count_friends=Count('friends'),
+ ).order_by()
+ _, _, group_by = qs.query.get_compiler(using='default').pre_sql_setup()
+ self.assertEqual(len(group_by), 1)
+ self.assertNotEqual(raw, group_by[0])
+
def test_defer_annotation(self):
"""
Deferred attributes can be referenced by an annotation,