mirror of
https://github.com/django/django.git
synced 2025-07-30 00:24:26 +00:00
Fixed #35339 -- Fixed PostgreSQL aggregate's filter and order_by params order.
Updated OrderableAggMixin.as_sql() to separate the order_by parameters from the filter parameters. Previously, the parameters and SQL were calculated by the Aggregate parent class, resulting in a mixture of order_by and filter parameters. Thanks Simon Charette for the review.
This commit is contained in:
parent
42b567ab4c
commit
c8df2f9941
2 changed files with 32 additions and 7 deletions
|
@ -12,7 +12,7 @@ from django.db.models import (
|
|||
Window,
|
||||
)
|
||||
from django.db.models.fields.json import KeyTextTransform, KeyTransform
|
||||
from django.db.models.functions import Cast, Concat, Substr
|
||||
from django.db.models.functions import Cast, Concat, LPad, Substr
|
||||
from django.test import skipUnlessDBFeature
|
||||
from django.test.utils import Approximate
|
||||
from django.utils import timezone
|
||||
|
@ -238,6 +238,16 @@ class TestGeneralAggregate(PostgreSQLTestCase):
|
|||
)
|
||||
self.assertEqual(values, {"arrayagg": ["en", "pl"]})
|
||||
|
||||
def test_array_agg_filter_and_ordering_params(self):
|
||||
values = AggregateTestModel.objects.aggregate(
|
||||
arrayagg=ArrayAgg(
|
||||
"char_field",
|
||||
filter=Q(json_field__has_key="lang"),
|
||||
ordering=LPad(Cast("integer_field", CharField()), 2, Value("0")),
|
||||
)
|
||||
)
|
||||
self.assertEqual(values, {"arrayagg": ["Foo2", "Foo4"]})
|
||||
|
||||
def test_array_agg_filter(self):
|
||||
values = AggregateTestModel.objects.aggregate(
|
||||
arrayagg=ArrayAgg("integer_field", filter=Q(integer_field__gt=0)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue