diff --git a/django/db/models/query.py b/django/db/models/query.py index 81a8b67cec..87bc6205a8 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 613f4c4cfc..fb0f09efde 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).