Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion django/db/backends/sqlite3/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ def check_expression_support(self, expression):
'aggregations on date/time fields in sqlite3 '
'since date/time is saved as text.'
)
if isinstance(expression, models.Aggregate) and len(expression.source_expressions) > 1:
if (
isinstance(expression, models.Aggregate) and
expression.distinct and
len(expression.source_expressions) > 1
):
raise NotSupportedError(
"SQLite doesn't support DISTINCT on aggregate functions "
"accepting multiple arguments."
Expand Down
9 changes: 9 additions & 0 deletions tests/backends/sqlite/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ class DistinctAggregate(Aggregate):
with self.assertRaisesMessage(NotSupportedError, msg):
connection.ops.check_expression_support(aggregate)

def test_distinct_aggregation_multiple_args_no_distinct(self):
# Aggregate functions accept multiple arguments when DISTINCT isn't
# used, e.g. GROUP_CONCAT().
class DistinctAggregate(Aggregate):
allow_distinct = True

aggregate = DistinctAggregate('first', 'second', distinct=False)
connection.ops.check_expression_support(aggregate)

def test_memory_db_test_name(self):
"""A named in-memory db should be allowed where supported."""
from django.db.backends.sqlite3.base import DatabaseWrapper
Expand Down