Opened 5 years ago

Closed 5 years ago

#31204 closed Bug (needsinfo)

Paginator with count = 0 always produce non-limited QuerySet.

Reported by: Alexander Pervakov Owned by: nobody
Component: Core (Other) Version: 3.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Problem:

Custom paginator, i.e. approximate PostgreSQL paginator based on pg_class.reltuples, could return count = 0 when vacuum haven't run yet. QuerySet doesn't set limit on following select query, and in my case I've got max memory exceeded error because Django Admin have tried to visualise all 3M rows from my DB.

Solution:

As a workaround for that case one should always use limit for one's custom count, a good candidate for this is a Paginator.per_page attribute.
Django itself could limits count as well, but when I've tried to implement it myself a 3 tests was failed (because in these tests Django Admin trust to ChangeList.result_count), and I've no time for deeper investigation.
So my github PR isn't going beyond and only point to this case in a docs and in a count method comment to help curious ones in their custom Paginator implementation.

Change History (1)

comment:1 by Mariusz Felisiak, 5 years ago

Component: contrib.adminCore (Other)
Has patch: unset
Resolution: needsinfo
Status: newclosed
Summary: Paginator with count = 0 always produce non-limited QuerySetPaginator with count = 0 always produce non-limited QuerySet.
Type: UncategorizedBug

Thanks for this report, however I'm sure how the fact that a custom paginator returned 0 in count() ended with a queryset without any limit. As far as I'm concerned builtin paginators return and empty queryset in such cases, so it looks like an issue in custom paginator implementation .

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