summaryrefslogtreecommitdiff
path: root/django/db/backends
diff options
context:
space:
mode:
authorMatthew Wilkes <git@matthewwilkes.name>2017-06-18 16:53:40 +0100
committerTim Graham <timograham@gmail.com>2018-02-10 19:08:55 -0500
commit2162f0983de0dfe2178531638ce7ea56f54dd4e7 (patch)
treebb1e859159200fa7ebeeaa02ec3908e1cf5d2655 /django/db/backends
parentbf26f66029bca94b007a2452679ac004598364a6 (diff)
Fixed #24747 -- Allowed transforms in QuerySet.order_by() and distinct(*fields).
Diffstat (limited to 'django/db/backends')
-rw-r--r--django/db/backends/base/operations.py4
-rw-r--r--django/db/backends/postgresql/operations.py7
2 files changed, 6 insertions, 5 deletions
diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py
index f6d8925278..465ac70b7b 100644
--- a/django/db/backends/base/operations.py
+++ b/django/db/backends/base/operations.py
@@ -158,7 +158,7 @@ class BaseDatabaseOperations:
"""
return ''
- def distinct_sql(self, fields):
+ def distinct_sql(self, fields, params):
"""
Return an SQL DISTINCT clause which removes duplicate rows from the
result set. If any fields are given, only check the given fields for
@@ -167,7 +167,7 @@ class BaseDatabaseOperations:
if fields:
raise NotSupportedError('DISTINCT ON fields is not supported by this database backend')
else:
- return 'DISTINCT'
+ return ['DISTINCT'], []
def fetch_returned_insert_id(self, cursor):
"""
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 3b71cd4f2c..6f48cfa228 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -207,11 +207,12 @@ class DatabaseOperations(BaseDatabaseOperations):
"""
return 63
- def distinct_sql(self, fields):
+ def distinct_sql(self, fields, params):
if fields:
- return 'DISTINCT ON (%s)' % ', '.join(fields)
+ params = [param for param_list in params for param in param_list]
+ return (['DISTINCT ON (%s)' % ', '.join(fields)], params)
else:
- return 'DISTINCT'
+ return ['DISTINCT'], []
def last_executed_query(self, cursor, sql, params):
# http://initd.org/psycopg/docs/cursor.html#cursor.query