Opened 13 years ago

Closed 12 years ago

#18139 closed Bug (duplicate)

ArchiveIndexView and YearIndexView compute the queryset twice

Reported by: Aymeric Augustin Owned by: Aymeric Augustin
Component: Generic views Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

In the debug toolbar, I noticed that the queryset is evaluated twice, with a different ordering. The call to order_by in get_dated_items appears to be the culprit.

I'm attaching a patch that resolves the issue, but it may not be backwards compatible -- the order of objects in classes inheriting BaseDateListView may change.

Attachments (1)

18139.diff (1.9 KB ) - added by Aymeric Augustin 13 years ago.

Download all attachments as: .zip

Change History (5)

by Aymeric Augustin, 13 years ago

Attachment: 18139.diff added

comment:1 by Aymeric Augustin, 13 years ago

A little bit more background:

  • MultipleObjectMixin.get_context_data sets context['object_list'] = context[get_context_object_name()] = queryset
  • BaseDateListView.get calls MultipleObjectMixin.get_context_data with two keyword arguments, object_list and date_list, that are computed by get_dated_items (a method that the subclasses must implement). Since keyword arguments have precedence over other variable, context['object_list'] is overwritten (and loses pagination).

So we end up with two slightly different variables in the context with similar purposes, one under 'object_list' and the other under the value of get_context_object_name().

comment:2 by Aymeric Augustin, 13 years ago

Owner: changed from nobody to Aymeric Augustin

comment:3 by Jannis Leidel, 12 years ago

Triage Stage: UnreviewedAccepted

Hm, this is kinda related to #18355, so this better be fixed together.

comment:4 by Aymeric Augustin, 12 years ago

Resolution: duplicate
Status: newclosed

It's actually a duplicate of #18354 which I fixed this morning. I forgot I had already reported it.

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