Fixed #19173 -- Made EmptyQuerySet a marker class only

The guarantee that no queries will be made when accessing results is
done by new EmptyWhere class which is used for query.where and having.

Thanks to Simon Charette for reviewing and valuable suggestions.
This commit is contained in:
Anssi Kääriäinen 2012-10-24 00:04:37 +03:00
parent a843539af2
commit a2396a4c8f
11 changed files with 96 additions and 177 deletions

View file

@ -4,6 +4,7 @@ from datetime import datetime
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.db.models.fields import Field, FieldDoesNotExist
from django.db.models.query import EmptyQuerySet
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.utils import six
from django.utils.translation import ugettext_lazy
@ -639,3 +640,9 @@ class ModelTest(TestCase):
Article.objects.bulk_create([Article(headline=lazy, pub_date=datetime.now())])
article = Article.objects.get()
self.assertEqual(article.headline, notlazy)
def test_emptyqs(self):
# Can't be instantiated
with self.assertRaises(TypeError):
EmptyQuerySet()
self.assertTrue(isinstance(Article.objects.none(), EmptyQuerySet))