summaryrefslogtreecommitdiff
path: root/django/db/models/sql/where.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/sql/where.py')
-rw-r--r--django/db/models/sql/where.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py
index 2b315be7c8..0fedb771b7 100644
--- a/django/db/models/sql/where.py
+++ b/django/db/models/sql/where.py
@@ -418,7 +418,9 @@ class SubqueryConstraint(object):
else:
query = query._clone()
query = query.query
- query.clear_ordering(True)
+ if query.can_filter():
+ # If there is no slicing in use, then we can safely drop all ordering
+ query.clear_ordering(True)
query_compiler = query.get_compiler(connection=connection)
return query_compiler.as_subquery_condition(self.alias, self.columns, qn)