Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit 5cc0f5f8c1f35218ee4bce2d8c943a86f1888b96 1 parent af2bb17
Anssi Kääriäinen authored February 10, 2013
4  django/db/models/query.py
@@ -500,7 +500,7 @@ def _earliest_or_latest(self, field_name=None, direction="-"):
500 500
             "Cannot change a query once a slice has been taken."
501 501
         obj = self._clone()
502 502
         obj.query.set_limits(high=1)
503  
-        obj.query.clear_ordering()
  503
+        obj.query.clear_ordering(force_empty=True)
504 504
         obj.query.add_ordering('%s%s' % (direction, order_by))
505 505
         return obj.get()
506 506
 
@@ -793,7 +793,7 @@ def order_by(self, *field_names):
793 793
         assert self.query.can_filter(), \
794 794
                 "Cannot reorder a query once a slice has been taken."
795 795
         obj = self._clone()
796  
-        obj.query.clear_ordering()
  796
+        obj.query.clear_ordering(force_empty=False)
797 797
         obj.query.add_ordering(*field_names)
798 798
         return obj
799 799
 
2  django/db/models/sql/query.py
@@ -1638,7 +1638,7 @@ def add_ordering(self, *ordering):
1638 1638
         else:
1639 1639
             self.default_ordering = False
1640 1640
 
1641  
-    def clear_ordering(self, force_empty=False):
  1641
+    def clear_ordering(self, force_empty):
1642 1642
         """
1643 1643
         Removes any ordering settings. If 'force_empty' is True, there will be
1644 1644
         no ordering in the resulting query (not even the model's default).

0 notes on commit 5cc0f5f

Please sign in to comment.
Something went wrong with that request. Please try again.