mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Fixed #28811 -- Fixed crash when combining regular and group by annotations.
This commit is contained in:
parent
2cb6b7732d
commit
fbf647287e
@ -1514,7 +1514,7 @@ class Query:
|
||||
# that case we need to return a Ref to the subquery's annotation.
|
||||
return Ref(name, self.annotation_select[name])
|
||||
else:
|
||||
return self.annotation_select[name]
|
||||
return self.annotations[name]
|
||||
else:
|
||||
field_list = name.split(LOOKUP_SEP)
|
||||
join_info = self.setup_joins(field_list, self.get_meta(), self.get_initial_alias(), can_reuse=reuse)
|
||||
|
@ -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()):
|
||||
|
Loading…
Reference in New Issue
Block a user