Ticket #14930: extra_order_by_values_list-17428.diff

File extra_order_by_values_list-17428.diff, 1.3 KB (added by Simon Litchfield, 13 years ago)

Fix- against r17428

  • django/db/models/query.py

     
    981981            self.extra_names = None
    982982            self.field_names = [f.attname for f in self.model._meta.fields]
    983983            self.aggregate_names = None
    984 
     984       
    985985        self.query.select = []
    986         if self.extra_names is not None:
    987             self.query.set_extra_mask(self.extra_names)
     986        extra_mask_names = self.extra_names + list(self.query.extra_order_by or [])
     987        if extra_mask_names is not None:
     988            self.query.set_extra_mask(extra_mask_names)
    988989        self.query.add_fields(self.field_names, True)
    989990        if self.aggregate_names is not None:
    990991            self.query.set_aggregate_mask(self.aggregate_names)
     
    10591060    def iterator(self):
    10601061        if self.flat and len(self._fields) == 1:
    10611062            for row in self.query.get_compiler(self.db).results_iter():
    1062                 yield row[0]
     1063                yield row[len(self.query.extra_select_mask)]
    10631064        elif not self.query.extra_select and not self.query.aggregate_select:
    10641065            for row in self.query.get_compiler(self.db).results_iter():
    10651066                yield tuple(row)
Back to Top