Ticket #14697: patch.diff

File patch.diff, 2.3 KB (added by Anssi Kääriäinen, 14 years ago)
  • django/db/models/query.py

    diff --git a/django/db/models/query.py b/django/db/models/query.py
    index d448dec..d0803c4 100644
    a b class QuerySet(object):  
    267267            model_cls = deferred_class_factory(self.model, skip)
    268268
    269269        compiler = self.query.get_compiler(using=self.db)
     270        db = self.db
    270271        for row in compiler.results_iter():
    271272            if fill_cache:
    272273                obj, _ = get_cached_row(self.model, row,
    class QuerySet(object):  
    283284                    obj = self.model(*row[index_start:aggregate_start])
    284285
    285286                # Store the source database of the object
    286                 obj._state.db = self.db
     287                obj._state.db = db
    287288
    288             for i, k in enumerate(extra_select):
    289                 setattr(obj, k, row[i])
     289            if extra_select:
     290                for i, k in enumerate(extra_select):
     291                    setattr(obj, k, row[i])
    290292
    291293            # Add the aggregates to the model
    292             for i, aggregate in enumerate(aggregate_select):
    293                 setattr(obj, aggregate, row[i+aggregate_start])
     294            if aggregate_select:
     295                for i, aggregate in enumerate(aggregate_select):
     296                    setattr(obj, aggregate, row[i+aggregate_start])
    294297
    295298            yield obj
    296299
  • django/db/models/sql/compiler.py

    diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
    index a11d556..b2249dc 100644
    a b class SQLCompiler(object):  
    672672        """
    673673        resolve_columns = hasattr(self, 'resolve_columns')
    674674        fields = None
     675        has_aggregate_select = bool(self.query.aggregate_select)
    675676        for rows in self.execute_sql(MULTI):
    676677            for row in rows:
    677678                if resolve_columns:
    class SQLCompiler(object):  
    692693                                      f.column in only_load[db_table]]
    693694                    row = self.resolve_columns(row, fields)
    694695
    695                 if self.query.aggregate_select:
     696                if has_aggregate_select:
    696697                    aggregate_start = len(self.query.extra_select.keys()) + len(self.query.select)
    697698                    aggregate_end = aggregate_start + len(self.query.aggregate_select)
    698699                    row = tuple(row[:aggregate_start]) + tuple([
Back to Top