Opened 9 years ago

Closed 9 years ago

#10915 closed (duplicate)

For QuerySet qs, list(qs)[k] does not always equal qs[k]

Reported by: David Gouldin Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords:
Cc: dgouldin@…, jdunck@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


On QuerySet.__getitem__ (i.e. qs[k]), a limit/offset is applied to a clone of the queryset. While I think the intent is to retrieve the kth item from the queryset just as it would have been if reached in the process of an iter (in other words, list(qs)[k] == qs[k] for all k), the limit/offset method of retrieval is inherently different due to a lack of ordering in the database.

This results in an unstable answer from __getitem__ for models without an order_by.

Change History (3)

comment:1 Changed 9 years ago by David Gouldin

Cc: dgouldin@… added

comment:2 Changed 9 years ago by Jeremy Dunck

Cc: jdunck@… added

comment:3 Changed 9 years ago by Karen Tracey

Resolution: duplicate
Status: newclosed

#9006 already requested/discussed providing a default ordering for a queryset and was eventually closed wontfix.

#10163 dealt with fixing the formset usage that depended on consistent ordering -- on both trunk and 1.0.X now, an ordering is applied if necessary. This was just fixed in the last day or so. If there are other parts of Django that depend on a consistent ordering, those should be raised as new issues. But changing the base queryset to apply an ordering when the user hasn't specified one isn't likely to happen.

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