From d68598e0220908ca82cf98ba769e618404c010c8 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 3 Dec 2010 20:25:59 +0000 Subject: Fixed #14700 -- ensure that a raw query is only executed once per iteration. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14785 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/query.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'django') diff --git a/django/db/models/query.py b/django/db/models/query.py index deb138119c..2323c7d744 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -1310,9 +1310,13 @@ class RawQuerySet(object): # Cache some things for performance reasons outside the loop. db = self.db - compiler = connections[db].ops.compiler('SQLCompiler')(self.query, connections[db], db) + compiler = connections[db].ops.compiler('SQLCompiler')( + self.query, connections[db], db + ) need_resolv_columns = hasattr(compiler, 'resolve_columns') + query = iter(self.query) + # Find out which columns are model's fields, and which ones should be # annotated to the model. for pos, column in enumerate(self.columns): @@ -1341,7 +1345,7 @@ class RawQuerySet(object): if need_resolv_columns: fields = [self.model_fields.get(c, None) for c in self.columns] # Begin looping through the query values. - for values in self.query: + for values in query: if need_resolv_columns: values = compiler.resolve_columns(values, fields) # Associate fields to values -- cgit v1.3