From 2c6d1e8ebc2d5d8cb62473dcb35f3c783aab6b95 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 27 Jul 2008 18:38:56 +0000 Subject: [PATCH] Fixed #7886 -- Reordered some code in Query.results_iter() to ensure that all the prequisites are correctly initialised prior to using them. Only affects Oracle and other db backends requiring resolve_columns() (e.g. MS SQL?) git-svn-id: http://code.djangoproject.com/svn/django/trunk@8112 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/sql/query.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 93a779e591..18dd8cc3f2 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -197,14 +197,18 @@ class Query(object): Returns an iterator over the results from executing this query. """ resolve_columns = hasattr(self, 'resolve_columns') - if resolve_columns: - if self.select_fields: - fields = self.select_fields + self.related_select_fields - else: - fields = self.model._meta.fields + fields = None for rows in self.execute_sql(MULTI): for row in rows: if resolve_columns: + if fields is None: + # We only set this up here because + # related_select_fields isn't populated until + # execute_sql() has been called. + if self.select_fields: + fields = self.select_fields + self.related_select_fields + else: + fields = self.model._meta.fields row = self.resolve_columns(row, fields) yield row