Revert "Fixed 19895 -- Made second iteration over invalid queryset raise an exception too"

This reverts commit 2cd0edaa47.
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:41:53 +01:00
parent ccb87f97ad
commit 23490a2394
2 changed files with 2 additions and 19 deletions

View File

@ -104,7 +104,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()
@ -341,18 +341,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

@ -3,7 +3,7 @@ from __future__ import absolute_import, unicode_literals
from datetime import datetime from datetime import datetime
import threading import threading
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.db import connections, DEFAULT_DB_ALIAS from django.db import connections, DEFAULT_DB_ALIAS
from django.db.models.fields import Field, FieldDoesNotExist from django.db.models.fields import Field, FieldDoesNotExist
from django.db.models.query import QuerySet, EmptyQuerySet, ValuesListQuerySet from django.db.models.query import QuerySet, EmptyQuerySet, ValuesListQuerySet
@ -689,11 +689,6 @@ class ModelTest(TestCase):
with self.assertNumQueries(0): with self.assertNumQueries(0):
self.assertEqual(len(Article.objects.none().distinct('headline', 'pub_date')), 0) self.assertEqual(len(Article.objects.none().distinct('headline', 'pub_date')), 0)
def test_invalid_qs_list(self):
qs = Article.objects.order_by('invalid_column')
self.assertRaises(FieldError, list, qs)
self.assertRaises(FieldError, list, qs)
class ConcurrentSaveTests(TransactionTestCase): class ConcurrentSaveTests(TransactionTestCase):
@skipUnlessDBFeature('test_db_allows_multiple_connections') @skipUnlessDBFeature('test_db_allows_multiple_connections')
def test_concurrent_delete_with_save(self): def test_concurrent_delete_with_save(self):