Michael Manfre avatar Michael Manfre committed 73acdcf

Fix bug introduced in changeset 66b87b26a50f that incorrectly mapped result row values to columns.

Comments (0)

Files changed (1)

sqlserver_ado/compiler.py

         # "row number" column. Remove this column before the ORM sees it.
         if getattr(self, '_using_row_number', False):
             row = row[1:]
-        
-        if not fields:
-            return row
+       
+        values = []
+        index_extra_select = len(self.query.extra_select.keys())
+        for value, field in map(None, row[index_extra_select:], fields):
+            if field:
+                internal_type = field.get_internal_type()
+                if internal_type == 'DateField' and isinstance(value, datetime.datetime):
+                    value = value.date()
+                elif internal_type == 'TimeField' and isinstance(value, datetime.datetime):
+                    value = value.time()
+            values.append(value)
 
-        new_row = []
-        for value, field in zip(row, fields):
-            internal_type = field.get_internal_type()
-            if internal_type == 'DateField' and isinstance(value, datetime.datetime):
-                new_row.append(value.date())
-            elif internal_type == 'TimeField' and isinstance(value, datetime.datetime):
-                new_row.append(value.time())    
-            else:
-                new_row.append(value)
-        return new_row
+        return row[:index_extra_select] + tuple(values)
 
     def as_sql(self, with_limits=True, with_col_aliases=False):
         self._using_row_number = False
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.