Opened 7 years ago

Closed 7 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: UI/UX:

Description

# paginator.py:36
    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@… 7 years ago.

Download all attachments as: .zip

Change History (2)

Changed 7 years ago by nicholasdsj@…

comment:1 Changed 7 years ago by ubernostrum

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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