[1.5.x] Revert "Fixed #19895 -- Made second iteration over invalid queryset raise an exception too"

This reverts commit d1e87eb3ba.
This commit was the cause of a memory leak. See ticket for more details.
Thanks Anssi Kääriäinen for identifying the source of the bug.
This commit is contained in:
Claude Paroz 2013-03-20 10:32:13 +01:00
parent 5c78877016
commit b91067d9aa
2 changed files with 2 additions and 19 deletions

View File

@ -102,7 +102,7 @@ class QuerySet(object):
len(self) len(self)
if self._result_cache is None: if self._result_cache is None:
self._iter = self._safe_iterator(self.iterator()) self._iter = self.iterator()
self._result_cache = [] self._result_cache = []
if self._iter: if self._iter:
return self._result_iter() return self._result_iter()
@ -337,18 +337,6 @@ class QuerySet(object):
yield obj yield obj
def _safe_iterator(self, iterator):
# ensure result cache is cleared when iterating over a queryset
# raises an exception
try:
for item in iterator:
yield item
except StopIteration:
raise
except Exception:
self._result_cache = None
raise
def aggregate(self, *args, **kwargs): def aggregate(self, *args, **kwargs):
""" """
Returns a dictionary containing the calculations (aggregation) Returns a dictionary containing the calculations (aggregation)

View File

@ -2,7 +2,7 @@ from __future__ import absolute_import, unicode_literals
from datetime import datetime from datetime import datetime
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.db.models.fields import Field, FieldDoesNotExist from django.db.models.fields import Field, FieldDoesNotExist
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.utils import six from django.utils import six
@ -639,8 +639,3 @@ class ModelTest(TestCase):
Article.objects.bulk_create([Article(headline=lazy, pub_date=datetime.now())]) Article.objects.bulk_create([Article(headline=lazy, pub_date=datetime.now())])
article = Article.objects.get() article = Article.objects.get()
self.assertEqual(article.headline, notlazy) self.assertEqual(article.headline, notlazy)
def test_invalid_qs_list(self):
qs = Article.objects.order_by('invalid_column')
self.assertRaises(FieldError, list, qs)
self.assertRaises(FieldError, list, qs)