Skip to content

Commit

Permalink
Made Query.clear_ordering force_empty arg mandatory
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akaariai committed Feb 10, 2013
1 parent af2bb17 commit 5cc0f5f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions django/db/models/query.py
Expand Up @@ -500,7 +500,7 @@ def _earliest_or_latest(self, field_name=None, direction="-"):
"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()

Expand Down Expand Up @@ -793,7 +793,7 @@ def order_by(self, *field_names):
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

Expand Down
2 changes: 1 addition & 1 deletion django/db/models/sql/query.py
Expand Up @@ -1638,7 +1638,7 @@ def add_ordering(self, *ordering):
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).
Expand Down

0 comments on commit 5cc0f5f

Please sign in to comment.