From 4d48ddd8f93800a80330ec1dee7b7d4afe6ea95a Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Sun, 15 Jul 2018 17:47:17 -0400 Subject: Fixed #28917 -- Prevented Paginator's unordered warning on EmptyQuerySet. Thanks carltongibson for the idea and weijunji for the initial patch. --- tests/pagination/tests.py | 6 ++++++ tests/queries/tests.py | 3 +++ 2 files changed, 9 insertions(+) (limited to 'tests') diff --git a/tests/pagination/tests.py b/tests/pagination/tests.py index f13afc308f..987e713405 100644 --- a/tests/pagination/tests.py +++ b/tests/pagination/tests.py @@ -1,4 +1,5 @@ import unittest +import warnings from datetime import datetime from django.core.paginator import ( @@ -368,6 +369,11 @@ class ModelPaginationTests(TestCase): # is appropriate). self.assertEqual(cm.filename, __file__) + def test_paginating_empty_queryset_does_not_warn(self): + with warnings.catch_warnings(record=True) as recorded: + Paginator(Article.objects.none(), 5) + self.assertEqual(len(recorded), 0) + def test_paginating_unordered_object_list_raises_warning(self): """ Unordered object list warning with an object that has an orderd diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 0d553c82d4..384bda4c77 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -2024,6 +2024,9 @@ class QuerysetOrderedTests(unittest.TestCase): def test_explicit_ordering(self): self.assertIs(Annotation.objects.all().order_by('id').ordered, True) + def test_empty_queryset(self): + self.assertIs(Annotation.objects.none().ordered, True) + def test_order_by_extra(self): self.assertIs(Annotation.objects.all().extra(order_by=['id']).ordered, True) -- cgit v1.3