#28284 closed Cleanup/optimization (fixed)
Paginator._check_object_list_is_ordered should not evaluate the entire queryset
Reported by: | Tom Forbes | Owned by: | Tom Forbes |
---|---|---|---|
Component: | Core (Other) | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The _check_object_list_is_ordered
function in Paginator currently throws a warning if the queryset is unordered. As part of this warning the queryset is formatted using {!r}
, which ends up calling the __repr__
or __str__
of each of the items in the QuerySet.
This causes the entire queryset to be evaluated and all rows fetched, and if __repr__
uses any foreign keys these are also fetched, resulting in a lot of queries. Warnings are also silent by default, and the string is *always* evaluated regardless of if the warning is displayed or not.
Also, the warning is conditional: Pagination *may* yield inconsistent results. Some databases may vary, so to people who use these backends this change just introduced something that evaluates the entire queryset every time the Paginator is used for no particular reason.
I propose that the warning is either replaced by a hard error, or the warning is changed to perhaps display the model name of the queryset, or some other information that doesn't require iterating the queryset.
Change History (5)
comment:1 by , 8 years ago
Summary: | Paginator._check_object_list_is_ordered should not call __repr__ on self.object_list → Paginator._check_object_list_is_ordered should not evaluate the entire queryset |
---|
comment:2 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Cleanup/optimization |
comment:3 by , 8 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
+1 for not evaluating the entire queryset.