diff options
| author | Robin Ramael <robin.ramael@maykinmedia.nl> | 2018-01-03 11:57:18 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-01-03 08:24:16 -0500 |
| commit | fbf647287ebd9898bff69c65a89fa09a903adaa5 (patch) | |
| tree | 940794cd820c93d541320576d500c02c2fbe0240 /tests | |
| parent | 2cb6b7732dc7b172797cebb1e8f19be2de89e264 (diff) | |
Fixed #28811 -- Fixed crash when combining regular and group by annotations.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/annotations/tests.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index d2e2214db8..ee1c50cfdf 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -527,6 +527,24 @@ class NonAggregateAnnotationTestCase(TestCase): self.assertIs(book.is_pony, False) self.assertIsNone(book.is_none) + def test_annotation_in_f_grouped_by_annotation(self): + qs = ( + Publisher.objects.annotate(multiplier=Value(3)) + # group by option => sum of value * multiplier + .values('name') + .annotate(multiplied_value_sum=Sum(F('multiplier') * F('num_awards'))) + .order_by() + ) + self.assertCountEqual( + qs, [ + {'multiplied_value_sum': 9, 'name': 'Apress'}, + {'multiplied_value_sum': 0, 'name': "Jonno's House of Books"}, + {'multiplied_value_sum': 27, 'name': 'Morgan Kaufmann'}, + {'multiplied_value_sum': 21, 'name': 'Prentice Hall'}, + {'multiplied_value_sum': 3, 'name': 'Sams'}, + ] + ) + def test_arguments_must_be_expressions(self): msg = 'QuerySet.annotate() received non-expression(s): %s.' with self.assertRaisesMessage(TypeError, msg % BooleanField()): |
