1
0
mirror of https://github.com/django/django.git synced 2025-10-27 07:36:08 +00:00

Fixed #28284 -- Prevented Paginator's unordered object list warning from evaluating a QuerySet.

This commit is contained in:
orf
2017-06-08 17:29:13 +01:00
committed by Tim Graham
parent 82175ead72
commit a118287bca
3 changed files with 29 additions and 6 deletions

View File

@@ -96,10 +96,16 @@ class Paginator:
"""
Warn if self.object_list is unordered (typically a QuerySet).
"""
if hasattr(self.object_list, 'ordered') and not self.object_list.ordered:
ordered = getattr(self.object_list, 'ordered', None)
if ordered is not None and not ordered:
obj_list_repr = (
'{} {}'.format(self.object_list.model, self.object_list.__class__.__name__)
if hasattr(self.object_list, 'model')
else '{!r}'.format(self.object_list)
)
warnings.warn(
'Pagination may yield inconsistent results with an unordered '
'object_list: {!r}'.format(self.object_list),
'object_list: {}.'.format(obj_list_repr),
UnorderedObjectListWarning,
stacklevel=3
)