                  self.aggregate_names != other.aggregate_names):
              raise TypeError("Merging '%s' classes must involve the same values in each case."
                      % self.__class__.__name__)
  
      def _setup_aggregate_query(self):
          """
          Prepare the query for computing a result that contains aggregate annotations.
          """
          self.query.set_group_by()
  
 
</s> remove     def _setup_aggregate_query(self):
 </s> add     def _setup_aggregate_query(self, aggregates): </s> remove         super(ValuesQuerySet, self)._setup_aggregate_query()
 </s> add         if self.aggregate_names is not None:
            self.aggregate_names.extend(aggregates)
            self.query.set_aggregate_mask(self.aggregate_names)

        super(ValuesQuerySet, self)._setup_aggregate_query(aggregates) </s> remove         obj._setup_aggregate_query()
 </s> add         obj._setup_aggregate_query(kwargs.keys()) </s> remove         query.aggregate_select[alias] = aggregate
 </s> add         query.aggregates[alias] = aggregate
    def _setup_aggregate_query(self, aggregates):
                  self.aggregate_names != other.aggregate_names):
              raise TypeError("Merging '%s' classes must involve the same values in each case."
                      % self.__class__.__name__)
  
    def _setup_aggregate_query(self, aggregates):
          """
          Prepare the query for computing a result that contains aggregate annotations.
          """
          self.query.set_group_by()
  
keep keep keep keep replace keep keep keep keep keep
 Fixed #10182 -- Corrected realiasing and the process of evaluating values() for queries with aggregate clauses. This means that aggregate queries can now be used as subqueries (such as in an __in clause). Thanks to omat for the report.

This involves a slight change to the interaction of annotate() and values() clauses that specify a list of columns. See the docs for details.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9888 bcc190cf-cafb-0310-a4f2-bffc1f526a37 
django/db/models/query.py