summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/db/backends/sqlite3/operations.py6
-rw-r--r--tests/backends/sqlite/tests.py9
2 files changed, 14 insertions, 1 deletions
diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py
index 83ee1489a6..80c32f6fcd 100644
--- a/django/db/backends/sqlite3/operations.py
+++ b/django/db/backends/sqlite3/operations.py
@@ -56,7 +56,11 @@ class DatabaseOperations(BaseDatabaseOperations):
'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."
diff --git a/tests/backends/sqlite/tests.py b/tests/backends/sqlite/tests.py
index c26377c8af..3898c8f13c 100644
--- a/tests/backends/sqlite/tests.py
+++ b/tests/backends/sqlite/tests.py
@@ -63,6 +63,15 @@ class Tests(TestCase):
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