Code

Opened 5 years ago

Closed 5 years ago

#10915 closed (duplicate)

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

Reported by: dgouldin 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:

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.

Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by dgouldin

  • Cc dgouldin@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by jdunck

  • Cc jdunck@… added

comment:3 Changed 5 years ago by kmtracey

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

#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.

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.