Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 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: UI/UX:

Description

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

Attachments (0)

Change History (5)

comment:1 Changed 6 years ago by programmerq

  • milestone set to 1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design 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 6 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 6 years ago by mtredinnick

  • Triage Stage changed from Design decision needed to Accepted

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 6 years ago by ubernostrum

  • Resolution set to fixed
  • Status changed from new to closed

(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 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.