mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[2.2.x] Fixed #30542 -- Fixed crash of numerical aggregations with filter.
Filters in annotations crashed when used with numerical-type aggregations (i.e. Avg, StdDev, and Variance). This was caused as the source expressions no not necessarily have an output_field (such as the filter field), which lead to an AttributeError: 'WhereNode' object has no attribute output_field. Thanks to Chuan-Zheng Lee for the report. Regression inc690afb873and two following commits. Backport of4b6dfe1622from master.
This commit is contained in:
committed by
Mariusz Felisiak
parent
ca3f86288a
commit
4e6f0024f1
@@ -42,9 +42,9 @@ class FixDurationInputMixin:
|
||||
class NumericOutputFieldMixin:
|
||||
|
||||
def _resolve_output_field(self):
|
||||
source_expressions = self.get_source_expressions()
|
||||
if any(isinstance(s.output_field, DecimalField) for s in source_expressions):
|
||||
source_fields = self.get_source_fields()
|
||||
if any(isinstance(s, DecimalField) for s in source_fields):
|
||||
return DecimalField()
|
||||
if any(isinstance(s.output_field, IntegerField) for s in source_expressions):
|
||||
if any(isinstance(s, IntegerField) for s in source_fields):
|
||||
return FloatField()
|
||||
return super()._resolve_output_field() if source_expressions else FloatField()
|
||||
return super()._resolve_output_field() if source_fields else FloatField()
|
||||
|
||||
Reference in New Issue
Block a user