summaryrefslogtreecommitdiff
path: root/django/contrib/postgres
diff options
context:
space:
mode:
authorChris Muthig <camuthig@gmail.com>2024-04-03 16:06:39 -0600
committernessita <124304+nessita@users.noreply.github.com>2024-04-25 17:40:03 -0300
commit42b567ab4c5bfb1bbd3e629b1079271c5ae44ea0 (patch)
treed5b727b4d6977099c37146de72099910598f6391 /django/contrib/postgres
parentec8552417df51df8482df61b8ad78a7002634011 (diff)
Refs #35339 -- Updated Aggregate class to return consistent source expressions.
Refactored the filter and order_by expressions in the Aggregate class to return a list of Expression (or None) values, ensuring that the list item is always available and represents the filter expression. For the PostgreSQL OrderableAggMixin, the returned list will always include the filter and the order_by value as the last two elements. Lastly, emtpy Q objects passed directly into aggregate objects using Aggregate.filter in admin facets are filtered out when resolving the expression to avoid errors in get_refs(). Thanks Simon Charette for the review.
Diffstat (limited to 'django/contrib/postgres')
-rw-r--r--django/contrib/postgres/aggregates/mixins.py7
1 files changed, 2 insertions, 5 deletions
diff --git a/django/contrib/postgres/aggregates/mixins.py b/django/contrib/postgres/aggregates/mixins.py
index 68f24a5ce3..527626da4c 100644
--- a/django/contrib/postgres/aggregates/mixins.py
+++ b/django/contrib/postgres/aggregates/mixins.py
@@ -17,13 +17,10 @@ class OrderableAggMixin:
return super().resolve_expression(*args, **kwargs)
def get_source_expressions(self):
- if self.order_by is not None:
- return super().get_source_expressions() + [self.order_by]
- return super().get_source_expressions()
+ return super().get_source_expressions() + [self.order_by]
def set_source_expressions(self, exprs):
- if isinstance(exprs[-1], OrderByList):
- *exprs, self.order_by = exprs
+ *exprs, self.order_by = exprs
return super().set_source_expressions(exprs)
def as_sql(self, compiler, connection):