Ticket #15624: aggregate_bug_quick_patch2.diff

File aggregate_bug_quick_patch2.diff, 1.4 KB (added by mwawrzyczek, 13 years ago)

Added more consistent version of the patch.

  • db/models/sql/query.py

     
    333333            # Return value depends on the type of the field being processed.
    334334            return self.convert_values(value, aggregate.field, connection)
    335335
     336    def disable_select_mask(self):
     337        self.old_mask = self.aggregate_select_mask.copy()
     338        self._aggregate_select_cache = None
     339        self.aggregate_select_mask = None
     340
     341    def restore_select_mask(self):
     342        self.aggregate_select_mask = self.old_mask
     343        self._aggregate_select_cache = None
     344
    336345    def get_aggregation(self, using):
    337346        """
    338347        Returns the dictionary with the values of the existing aggregations.
     
    344353        # information but retrieves only the first row. Aggregate
    345354        # over the subquery instead.
    346355        if self.group_by is not None:
     356            self.disable_select_mask()
     357
    347358            from django.db.models.sql.subqueries import AggregateQuery
    348359            query = AggregateQuery(self.model)
    349360
     
    356367                    query.aggregate_select[alias] = aggregate
    357368                    del obj.aggregate_select[alias]
    358369
     370            self.restore_select_mask()
     371
    359372            try:
    360373                query.add_subquery(obj, using)
    361374            except EmptyResultSet:
Back to Top