Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#8154 closed (fixed)

QuerySet.reverse() not working as documented

Reported by: casseen Owned by: nobody
Component: Documentation Version: master
Severity: Keywords: queryset reverse ordering
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The Documentation suggests that you can call the reverse() function on any queryset.

QuerySet.reverse() is only working if there is specified a default ordering in the model's meta options or the queryset has been ordered with QuerySet.order_by() previously

Change History (5)

comment:1 Changed 10 years ago by Jeff Anderson

milestone: 1.0
Triage Stage: UnreviewedDesign decision needed

I believe that this is likely a documentation issue. If I recall correctly, without an order_by statement in the actual SQL statement, the database itself isn't necessarily bound to returning anything in any particular order. Reversing something without an order doesn't make sense. Perhaps I'm wrong. Marking DDN.

comment:2 Changed 10 years ago by casseen

Yes, reverse() should not work on unordered querylist objects. I think it just has to be documented correctly. And it may throw an exception or warning when using on unordered objects.

comment:3 Changed 10 years ago by Malcolm Tredinnick

Triage Stage: Design decision neededAccepted

The eventual patch here should just say that the results are undetermined if you use it on an unordered queryset. It shouldn't raise an error or a warning so that you can safely call reverse() on something without worrying about whether it's ordered or not. It's harmless to do so, just not particularly useful. So this is a documentation-only issue.

comment:4 Changed 10 years ago by James Bennett

Resolution: fixed
Status: newclosed

(In [8371]) Fixed #8154: Added note to docs/db-api.txt indicating that reverse() is only useful when the QuerySet has some prior ordering

comment:5 Changed 7 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top