Repository: django/django
File: django/db/models/aggregates.py (Python)

Code before:
        c = self.copy()
        # The creation of the delimiter SQL and the ordering of the parameters
        # must be handled explicitly, as MySQL puts the delimiter at the end of
        # the aggregate using the `SEPARATOR` declaration (rather than treating
        # as an expression like other database backends).
        delimiter_params = []
        if c.delimiter:
            delimiter_sql, delimiter_params = compiler.compile(c.delimiter)
            # Drop the delimiter from the source expressions.
            c.source_expressions = c.source_expressions[:-1]
            extra_context["delimiter"] = delimiter_sql

        sql, params = c.as_sql(compiler, connection, **extra_context)

        return sql, (*params, *delimiter_params)

    def as_sqlite(self, compiler, connection, **extra_context):
        if self.distinct:
            expressions = self.get_source_expressions()
            if len(expressions) > 1:
                delimiter_expr = expressions[1]

                while hasattr(delimiter_expr, "value"):
                    delimiter_expr = delimiter_expr.value

                if delimiter_expr == ",":
                    clone = self.copy()
                    new_expressions = expressions[:1] + expressions[2:]
                    clone.set_source_expressions(new_expressions)
                    return clone.as_sql(
                        compiler,
                        connection,
                        function="GROUP_CONCAT",
                        template="%(function)s(%(distinct)s%(expressions)s)",
                        **extra_context,
                    )

        if connection.get_database_version() < (3, 44):
            return self.as_sql(
                compiler,
                connection,
                function="GROUP_CONCAT",
                **extra_context,
            )

        return self.as_sql(compiler, connection, **extra_context)


class Sum(FixDurationInputMixin, Aggregate):
    function = "SUM"
    name = "Sum"

Review comment (suggestion):
```suggestion
        if (
            self.distinct
            and isinstance(self.delimiter.value, Value)
            and self.delimiter.value.value == ","
        ):
            return ...
```

Code after:
        c = self.copy()
        # The creation of the delimiter SQL and the ordering of the parameters
        # must be handled explicitly, as MySQL puts the delimiter at the end of
        # the aggregate using the `SEPARATOR` declaration (rather than treating
        # as an expression like other database backends).
        delimiter_params = []
        if c.delimiter:
            delimiter_sql, delimiter_params = compiler.compile(c.delimiter)
            # Drop the delimiter from the source expressions.
            c.source_expressions = c.source_expressions[:-1]
            extra_context["delimiter"] = delimiter_sql

        sql, params = c.as_sql(compiler, connection, **extra_context)

        return sql, (*params, *delimiter_params)

    def as_sqlite(self, compiler, connection, **extra_context):
        if (
            self.distinct
            and isinstance(self.delimiter.value, Value)
            and self.delimiter.value.value == ","
        ):
            clone = self.copy()
            source_expressions = clone.get_source_expressions()
            clone.set_source_expressions(
                source_expressions[:1] + source_expressions[2:]
            )

            return clone.as_sql(
                compiler,
                connection,
                function="GROUP_CONCAT",
                **extra_context,
            )

        if connection.get_database_version() < (3, 44):
            return self.as_sql(
                compiler,
                connection,
                function="GROUP_CONCAT",
                **extra_context,
            )

        return self.as_sql(compiler, connection, **extra_context)


class Sum(FixDurationInputMixin, Aggregate):
    function = "SUM"
    name = "Sum"
    allow_distinct = True
    arity = 1