  
          self.query.select = []
          self.query.add_fields(self.field_names, False)
  
      def _clone(self, klass=None, setup=False, **kwargs):
          """
          Cloning a ValuesQuerySet preserves the current fields.
          """
          c = super(ValuesQuerySet, self)._clone(klass, **kwargs)
 
</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     def _setup_aggregate_query(self):
 </s> add     def _setup_aggregate_query(self, aggregates): </s> remove         self.aggregate_select = SortedDict() # Maps alias -> SQL aggregate function
 </s> add         self.aggregates = SortedDict() # Maps alias -> SQL aggregate function
        self.aggregate_select_mask = None
        self._aggregate_select_cache = None </s> remove         obj.aggregate_select = self.aggregate_select.copy()
 </s> add         obj.aggregates = self.aggregates.copy()
        if self.aggregate_select_mask is None:
            obj.aggregate_select_mask = None
        else:
            obj.aggregate_select_mask = self.aggregate_select_mask[:]
        if self._aggregate_select_cache is None:
            obj._aggregate_select_cache = None
        else:
            obj._aggregate_select_cache = self._aggregate_select_cache.copy()
        if self.aggregate_names is not None:
            self.query.set_aggregate_mask(self.aggregate_names)
  
          self.query.select = []
          self.query.add_fields(self.field_names, False)
        if self.aggregate_names is not None:
            self.query.set_aggregate_mask(self.aggregate_names)
  
      def _clone(self, klass=None, setup=False, **kwargs):
          """
          Cloning a ValuesQuerySet preserves the current fields.
          """
          c = super(ValuesQuerySet, self)._clone(klass, **kwargs)
keep keep add keep 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