Commits

Anonymous committed 00acb28

queryset-refactor: Make sure the right list of fields is passed to the
Query.resolve_columns() method for those backends that provide it (e.g. Oracle).

Refs #7088

Comments (0)

Files changed (2)

django/db/models/sql/query.py

         self.standard_ordering = True
         self.ordering_aliases = []
         self.start_meta = None
+        self.select_fields = []
+        self.related_select_fields = []
 
         # SQL-related attributes
         self.select = []
         obj.standard_ordering = self.standard_ordering
         obj.ordering_aliases = []
         obj.start_meta = self.start_meta
+        obj.select_fields = self.select_fields[:]
+        obj.related_select_fields = self.related_select_fields[:]
         obj.select = self.select[:]
         obj.tables = self.tables[:]
         obj.where = deepcopy(self.where)
         """
         Returns an iterator over the results from executing this query.
         """
-        fields = self.model._meta.fields
         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
         for rows in self.execute_sql(MULTI):
             for row in rows:
                 if resolve_columns:
         obj.clear_limits()
         obj.select_related = False
         obj.related_select_cols = []
+        obj.related_select_fields = []
         if obj.distinct and len(obj.select) > 1:
             obj = self.clone(CountQuery, _query=obj, where=self.where_class(),
                     distinct=False)
         number = data[0]
 
         # Apply offset and limit constraints manually, since using LIMIT/OFFSET
-        # in SQL doesn't change the COUNT output.
+        # in SQL (in variants that provide them) doesn't change the COUNT
+        # output.
         number = max(0, number - self.low_mark)
         if self.high_mark:
             number = min(number, self.high_mark - self.low_mark)
                 item = deepcopy(col)
                 item.relabel_aliases(change_map)
                 self.select.append(item)
+        self.select_fields = rhs.select_fields[:]
         self.extra_select = rhs.extra_select.copy()
         self.extra_tables = rhs.extra_tables
         self.extra_where = rhs.extra_where
             opts = self.get_meta()
             root_alias = self.get_initial_alias()
             self.related_select_cols = []
+            self.related_select_fields = []
         if not used:
             used = set()
 
             used.add(alias)
             self.related_select_cols.extend([(alias, f2.column)
                     for f2 in f.rel.to._meta.fields])
+            self.related_select_fields.extend(f.rel.to._meta.fields)
             if restricted:
                 next = requested.get(f.name, {})
             else:
         opts = self.get_meta()
         try:
             for name in field_names:
-                u1, target, u2, joins, u3 = self.setup_joins(
+                field, target, u2, joins, u3 = self.setup_joins(
                         name.split(LOOKUP_SEP), opts, alias, False, allow_m2m,
                         True)
                 final_alias = joins[-1]
                     # doing unnecessary left outer joins here.
                     self.promote_alias(join)
                 self.select.append((final_alias, col))
+                self.select_fields.append(field)
         except MultiJoin:
             raise FieldError("Invalid field name: '%s'" % name)
         except FieldError:
             # level.
             self.distinct = False
         self.select = [select]
+        self.select_fields = [None]
         self.extra_select = {}
         self.extra_select_params = ()
 
                 d = d.setdefault(part, {})
         self.select_related = field_dict
         self.related_select_cols = []
+        self.related_select_fields = []
 
     def add_extra(self, select, select_params, where, params, tables, order_by):
         """
                 start.split(LOOKUP_SEP), opts, alias, False)
         alias = joins[last[-1]]
         self.select = [(alias, self.alias_map[alias][RHS_JOIN_COL])]
+        self.select_fields = [field]
         self.start_meta = opts
 
         # The call to setup_joins add an extra reference to everything in

django/db/models/sql/subqueries.py

         select = Date((alias, column), lookup_type,
                 self.connection.ops.date_trunc_sql)
         self.select = [select]
+        self.select_fields = [None]
         self.distinct = True
         self.order_by = order == 'ASC' and [1] or [-1]
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.