Opened 13 years ago
Closed 13 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)
Change History (5)
by , 13 years ago
Attachment: | 18139.diff added |
---|
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Owner: | changed from | to
---|
comment:3 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Hm, this is kinda related to #18355, so this better be fixed together.
comment:4 by , 13 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
It's actually a duplicate of #18354 which I fixed this morning. I forgot I had already reported it.
A little bit more background:
MultipleObjectMixin.get_context_data
setscontext['object_list'] = context[get_context_object_name()] = queryset
BaseDateListView.get
callsMultipleObjectMixin.get_context_data
with two keyword arguments,object_list
anddate_list
, that are computed byget_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 ofget_context_object_name()
.