Fixed #32166 -- Removed redundant definition of Greatest in test_expression_on_aggregation.
This commit is contained in:
parent
cfc7cd6513
commit
09e1ec71df
|
@ -5,10 +5,10 @@ from decimal import Decimal
|
||||||
from django.core.exceptions import FieldError
|
from django.core.exceptions import FieldError
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db.models import (
|
from django.db.models import (
|
||||||
Avg, Case, Count, DecimalField, DurationField, Exists, F, FloatField, Func,
|
Avg, Case, Count, DecimalField, DurationField, Exists, F, FloatField,
|
||||||
IntegerField, Max, Min, OuterRef, Subquery, Sum, Value, When,
|
IntegerField, Max, Min, OuterRef, Subquery, Sum, Value, When,
|
||||||
)
|
)
|
||||||
from django.db.models.functions import Coalesce
|
from django.db.models.functions import Coalesce, Greatest
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.testcases import skipUnlessDBFeature
|
from django.test.testcases import skipUnlessDBFeature
|
||||||
from django.test.utils import Approximate, CaptureQueriesContext
|
from django.test.utils import Approximate, CaptureQueriesContext
|
||||||
|
@ -1102,14 +1102,6 @@ class AggregateTestCase(TestCase):
|
||||||
{'books_per_rating__max': 3 + 5})
|
{'books_per_rating__max': 3 + 5})
|
||||||
|
|
||||||
def test_expression_on_aggregation(self):
|
def test_expression_on_aggregation(self):
|
||||||
|
|
||||||
# Create a plain expression
|
|
||||||
class Greatest(Func):
|
|
||||||
function = 'GREATEST'
|
|
||||||
|
|
||||||
def as_sqlite(self, compiler, connection, **extra_context):
|
|
||||||
return super().as_sql(compiler, connection, function='MAX', **extra_context)
|
|
||||||
|
|
||||||
qs = Publisher.objects.annotate(
|
qs = Publisher.objects.annotate(
|
||||||
price_or_median=Greatest(Avg('book__rating', output_field=DecimalField()), Avg('book__price'))
|
price_or_median=Greatest(Avg('book__rating', output_field=DecimalField()), Avg('book__price'))
|
||||||
).filter(price_or_median__gte=F('num_awards')).order_by('num_awards')
|
).filter(price_or_median__gte=F('num_awards')).order_by('num_awards')
|
||||||
|
|
Loading…
Reference in New Issue