Ticket #27729: evaluate.diff
File evaluate.diff, 2.5 KB (added by , 8 years ago) |
---|
-
django/db/models/query.py
diff --git a/django/db/models/query.py b/django/db/models/query.py index e059c68..6ed6e08 100644
a b class QuerySet(object): 992 992 clone._db = alias 993 993 return clone 994 994 995 def evaluate(self): 996 """ 997 Returns a new, evaluated QuerySet instance. 998 """ 999 clone = self._clone() 1000 clone._fetch_all() 1001 return clone 1002 1003 995 1004 ################################### 996 1005 # PUBLIC INTROSPECTION ATTRIBUTES # 997 1006 ################################### -
tests/queries/tests.py
diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 8f0af65..3921510 100644
a b from operator import attrgetter 8 8 9 9 from django.core.exceptions import EmptyResultSet, FieldError 10 10 from django.db import DEFAULT_DB_ALIAS, connection 11 from django.db.models import Count, F, Q 11 from django.db.models import Count, F, Q, QuerySet 12 12 from django.db.models.sql.constants import LOUTER 13 13 from django.db.models.sql.where import NothingNode, WhereNode 14 14 from django.test import TestCase, skipUnlessDBFeature … … class Ticket23622Tests(TestCase): 3797 3797 set(Ticket23605A.objects.filter(qy).values_list('pk', flat=True)) 3798 3798 ) 3799 3799 self.assertSequenceEqual(Ticket23605A.objects.filter(qx), [a2]) 3800 3801 3802 class EvaluateMethodTests(TestCase): 3803 @classmethod 3804 def setUpTestData(cls): 3805 Number.objects.create(num=4) 3806 Number.objects.create(num=4) 3807 Number.objects.create(num=8) 3808 3809 def test_evaluate_allows_chain_methods(self): 3810 """ 3811 Tests that evaluate indeed returns a QuerySet. 3812 """ 3813 numbers = Number.objects.evaluate() 3814 self.assertIsInstance(numbers, QuerySet) 3815 3816 def test_evaluate_populates_result_cache(self): 3817 """ 3818 Tests that evaluate() populates the result cache. 3819 """ 3820 numbers = Number.objects.filter(num__lte=6) 3821 self.assertIsNone(numbers._result_cache) 3822 numbers = numbers.evaluate() 3823 self.assertTrue(numbers._result_cache) 3824 3825 def test_evaluate_does_not_query_database(self): 3826 """ 3827 Tests that subsequent QuerySet operations does not query the database after evaluate have been called. 3828 """ 3829 def test_function(): 3830 numbers = Number.objects.filter(num__lte=6) 3831 numbers = numbers.evaluate() 3832 numbers = numbers.filter(num__lte=5) 3833 3834 self.assertNumQueries(1, lambda: test_function())