From 7f8bd1a4b39ed834dffa0adc8fa19ef6b807f45d Mon Sep 17 00:00:00 2001 From: Justin Hamade Date: Mon, 14 Apr 2014 16:11:52 -0400 Subject: [1.7.x] Fixed #22434 -- Retain ordering on related sliced subqueries. Thanks maciej.pawlisz for the report, and charettes for the review. Backport of a13df671a5 from master --- django/db/models/sql/where.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'django/db/models/sql') 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) -- cgit v1.3