'Expand the GROUP BY clause required by the query.
This will usually be the set of all non-aggregate fields in the
return data. If the database backend supports grouping by the
primary key, and the query would be equivalent, the optimization
will be made automatically.'

def set_group_by(self):

    group_by = list(self.select)
    if self.annotation_select:
        for (alias, annotation) in self.annotation_select.items():
            for col in annotation.get_group_by_cols():
                group_by.append(col)
    self.group_by = tuple(group_by)
