Opened 16 years ago

Closed 16 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: no UI/UX: no

Description

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 by David Gouldin, 16 years ago

Cc: dgouldin@… added

comment:2 by Jeremy Dunck, 16 years ago

Cc: jdunck@… added

comment:3 by Karen Tracey, 16 years ago

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