Kaydet (Commit) 5cc0f5f8 authored tarafından Anssi Kääriäinen's avatar Anssi Kääriäinen

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.
üst af2bb174
......@@ -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
......
......@@ -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).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment