  
          # test completely changing how the output is rendered
          def lower_case_function_override(self, compiler, connection):
              sql, params = compiler.compile(self.source_expressions[0])
              substitutions = {'function': self.function.lower(), 'expressions': sql}
              substitutions.update(self.extra)
              return self.template % substitutions, params
          setattr(MySum, 'as_' + connection.vendor, lower_case_function_override)
  
          qs = Book.objects.annotate(
 
</s> remove             substitutions = {'function': 'MAX', 'expressions': '2'}
 </s> add             substitutions = {'function': 'MAX', 'expressions': '2', 'distinct': ''} </s> remove     def __init__(self, *args, filter=None, **kwargs):
 </s> add     def __init__(self, *expressions, distinct=False, filter=None, **extra):
        if distinct and not self.allow_distinct:
            raise TypeError("%s does not allow distinct." % self.__class__.__name__)
        self.distinct = distinct </s> remove         super().__init__(*args, **kwargs)
 </s> add         super().__init__(*expressions, **extra) </s> remove     def __init__(self, expression, delimiter, distinct=False, **extra):
        distinct = 'DISTINCT ' if distinct else ''
        super().__init__(expression, delimiter=delimiter, distinct=distinct, **extra)
 </s> add     def __init__(self, expression, delimiter, **extra):
        super().__init__(expression, delimiter=delimiter, **extra)
            substitutions = {'function': self.function.lower(), 'expressions': sql, 'distinct': ''}
  
          # test completely changing how the output is rendered
          def lower_case_function_override(self, compiler, connection):
              sql, params = compiler.compile(self.source_expressions[0])
            substitutions = {'function': self.function.lower(), 'expressions': sql, 'distinct': ''}
              substitutions.update(self.extra)
              return self.template % substitutions, params
          setattr(MySum, 'as_' + connection.vendor, lower_case_function_override)
  
          qs = Book.objects.annotate(
keep keep keep keep replace keep keep keep keep keep
 Fixed #28658 -- Added DISTINCT handling to the Aggregate class. 
tests/aggregation/tests.py