diff --git a/django/contrib/gis/db/models/aggregates.py b/django/contrib/gis/db/models/aggregates.py index 7ba2e756e7..abff1a5206 100644 --- a/django/contrib/gis/db/models/aggregates.py +++ b/django/contrib/gis/db/models/aggregates.py @@ -34,17 +34,14 @@ class GeoAggregate(Aggregate): tolerance = self.extra.get("tolerance") or getattr(self, "tolerance", 0.05) clone = self.copy() source_expressions = self.get_source_expressions() - if self.filter: - source_expressions.pop() + source_expressions.pop() # Don't wrap filters with SDOAGGRTYPE(). spatial_type_expr = Func( *source_expressions, Value(tolerance), function="SDOAGGRTYPE", output_field=self.output_field, ) - source_expressions = [spatial_type_expr] - if self.filter: - source_expressions.append(self.filter) + source_expressions = [spatial_type_expr, self.filter] clone.set_source_expressions(source_expressions) return clone.as_sql(compiler, connection, **extra_context) return self.as_sql(compiler, connection, **extra_context)