Skip to content

Commit

Permalink
[1.2.X] Fixed #14366 -- Model.objects.none().values() now correctly r…
Browse files Browse the repository at this point in the history
…eturns 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
  • Loading branch information
alex committed Oct 9, 2010
1 parent 2e5f0c2 commit bb66cb8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django/db/models/query.py
Expand Up @@ -1021,7 +1021,7 @@ def delete(self):
pass pass


def _clone(self, klass=None, setup=False, **kwargs): 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 = [] c._result_cache = []
return c return c


Expand Down
8 changes: 7 additions & 1 deletion tests/regressiontests/queries/tests.py
Expand Up @@ -4,7 +4,7 @@
from django.db.models import Count from django.db.models import Count
from django.test import TestCase 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): class QuerysetOrderedTests(unittest.TestCase):
""" """
Expand Down Expand Up @@ -81,3 +81,9 @@ def test_evaluated_queryset_as_argument(self):
self.assertEquals(ExtraInfo.objects.filter(note__in=n_list)[0].info, 'good') self.assertEquals(ExtraInfo.objects.filter(note__in=n_list)[0].info, 'good')
except: except:
self.fail('Query should be clonable') 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')), [])

0 comments on commit bb66cb8

Please sign in to comment.