1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #31659 -- Made ExpressionWrapper preserve output_field for combined expressions.

Regression in df32fd42b8.

Thanks Simon Charette for the review.
This commit is contained in:
Mariusz Felisiak
2020-06-11 11:29:14 +02:00
parent 5776a1660e
commit aeb8996a67
3 changed files with 14 additions and 1 deletions

View File

@@ -170,6 +170,14 @@ class NonAggregateAnnotationTestCase(TestCase):
self.assertEqual(book.is_book, 1)
self.assertEqual(book.rating_count, 1)
def test_combined_expression_annotation_with_aggregation(self):
book = Book.objects.annotate(
combined=ExpressionWrapper(Value(3) * Value(4), output_field=IntegerField()),
rating_count=Count('rating'),
).first()
self.assertEqual(book.combined, 12)
self.assertEqual(book.rating_count, 1)
def test_aggregate_over_annotation(self):
agg = Author.objects.annotate(other_age=F('age')).aggregate(otherage_sum=Sum('other_age'))
other_agg = Author.objects.aggregate(age_sum=Sum('age'))