From 5cc0f5f8c1f35218ee4bce2d8c943a86f1888b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Sun, 10 Feb 2013 20:52:52 +0200 Subject: [PATCH] Made Query.clear_ordering force_empty arg mandatory Previously it was possible to call clear_ordering without the force_empty argument. The result was that the query was still ordered by model's meta ordering if that was defined. By making the arg mandatory it will be easier to spot possible errors caused by assuming clear_ordering will remove all ordering. Thanks to Dylan Klomparens for the suggestion. Refs #19720. --- django/db/models/query.py | 4 ++-- django/db/models/sql/query.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index 81a8b67ceca..87bc6205a88 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -500,7 +500,7 @@ class QuerySet(object): "Cannot change a query once a slice has been taken." obj = self._clone() obj.query.set_limits(high=1) - obj.query.clear_ordering() + obj.query.clear_ordering(force_empty=True) obj.query.add_ordering('%s%s' % (direction, order_by)) return obj.get() @@ -793,7 +793,7 @@ class QuerySet(object): assert self.query.can_filter(), \ "Cannot reorder a query once a slice has been taken." obj = self._clone() - obj.query.clear_ordering() + obj.query.clear_ordering(force_empty=False) obj.query.add_ordering(*field_names) return obj diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 613f4c4cfc7..fb0f09efded 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1638,7 +1638,7 @@ class Query(object): else: self.default_ordering = False - def clear_ordering(self, force_empty=False): + def clear_ordering(self, force_empty): """ Removes any ordering settings. If 'force_empty' is True, there will be no ordering in the resulting query (not even the model's default).