Opened 11 years ago

Closed 11 years ago

#7091 closed (invalid)

Paginator failed to use 'limit' statement for MySQL

Reported by: nicholasdsj@… Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords: paginator mysql
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


    def _get_count(self):
        "Returns the total number of objects, across all pages."
        if self._count is None:
            self._count = len(self.object_list)
        return self._count
    count = property(_get_count)

len(self.object_list) will force a query without 'limit' statement, it's very severe problem. Instead of using len() method, an alternative way is to use self.object_list.count()

Attachments (1)

paginator_patch.diff (462 bytes) - added by nicholasdsj@… 11 years ago.

Download all attachments as: .zip

Change History (2)

Changed 11 years ago by nicholasdsj@…

Attachment: paginator_patch.diff added

comment:1 Changed 11 years ago by James Bennett

Resolution: invalid
Status: newclosed

Paginator is meant to work with any arbitrary iterable of objects, and so cannot assume that a QuerySet-specific method is available. If you're paginating a QuerySet, use QuerySetPaginator instead, which is in the same file and uses count().

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