mirror of
https://github.com/django/django.git
synced 2025-10-27 07:36:08 +00:00
Fixed #29244 -- Prevented Paginator.count() from silencing TypeError and AttributeError.
This commit is contained in:
committed by
Tim Graham
parent
f1bf069ec1
commit
3767c7ff39
@@ -1,8 +1,10 @@
|
||||
import collections.abc
|
||||
import inspect
|
||||
import warnings
|
||||
from math import ceil
|
||||
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.inspect import method_has_no_args
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
@@ -83,13 +85,10 @@ class Paginator:
|
||||
@cached_property
|
||||
def count(self):
|
||||
"""Return the total number of objects, across all pages."""
|
||||
try:
|
||||
return self.object_list.count()
|
||||
except (AttributeError, TypeError):
|
||||
# AttributeError if object_list has no count() method.
|
||||
# TypeError if object_list.count() requires arguments
|
||||
# (i.e. is of type list).
|
||||
return len(self.object_list)
|
||||
c = getattr(self.object_list, 'count', None)
|
||||
if callable(c) and not inspect.isbuiltin(c) and method_has_no_args(c):
|
||||
return c()
|
||||
return len(self.object_list)
|
||||
|
||||
@cached_property
|
||||
def num_pages(self):
|
||||
|
||||
Reference in New Issue
Block a user