summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2010-10-09 16:46:25 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2010-10-09 16:46:25 +0000
commitbb66cb8463190a0d65b920f44f50c23da9f58bd7 (patch)
tree92675ef21960104b8d154779b59bf165c6ce6798
parent2e5f0c228fb7bf65c83d8d83f3237db6a5e5ccb4 (diff)
[1.2.X] Fixed #14366 -- Model.objects.none().values() now correctly returns a QuerySet with no items, rather than raising an Exception. Thanks to Carl Meyer for the patch. Backport of [14084].
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14085 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/query.py2
-rw-r--r--tests/regressiontests/queries/tests.py8
2 files changed, 8 insertions, 2 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index def50934b7..18c7db6333 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -1021,7 +1021,7 @@ class EmptyQuerySet(QuerySet):
pass
def _clone(self, klass=None, setup=False, **kwargs):
- c = super(EmptyQuerySet, self)._clone(klass, **kwargs)
+ c = super(EmptyQuerySet, self)._clone(klass, setup=setup, **kwargs)
c._result_cache = []
return c
diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
index 03c28b06a7..75653fc660 100644
--- a/tests/regressiontests/queries/tests.py
+++ b/tests/regressiontests/queries/tests.py
@@ -4,7 +4,7 @@ from django.db import DatabaseError, connections, DEFAULT_DB_ALIAS
from django.db.models import Count
from django.test import TestCase
-from models import Tag, Annotation, DumbCategory, Note, ExtraInfo
+from models import Tag, Annotation, DumbCategory, Note, ExtraInfo, Number
class QuerysetOrderedTests(unittest.TestCase):
"""
@@ -81,3 +81,9 @@ class CloneTests(TestCase):
self.assertEquals(ExtraInfo.objects.filter(note__in=n_list)[0].info, 'good')
except:
self.fail('Query should be clonable')
+
+
+class EmptyQuerySetTests(TestCase):
+ def test_emptyqueryset_values(self):
+ "#14366 -- calling .values() on an EmptyQuerySet and then cloning that should not cause an error"
+ self.assertEqual(list(Number.objects.none().values('num').order_by('num')), [])