Opened 4 years ago

Closed 4 years ago

#18139 closed Bug (duplicate)

ArchiveIndexView and YearIndexView compute the queryset twice

Reported by: aaugustin Owned by: aaugustin
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


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 aaugustin 4 years ago.

Download all attachments as: .zip

Change History (5)

Changed 4 years ago by aaugustin

comment:1 Changed 4 years ago by aaugustin

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 Changed 4 years ago by aaugustin

  • Owner changed from nobody to aaugustin

comment:3 Changed 4 years ago by jezdez

  • Triage Stage changed from Unreviewed to Accepted

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

comment:4 Changed 4 years ago by aaugustin

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

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