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

Code before:

    def as_postgresql(self, compiler, connection, **extra_context):
        if connection.features.is_postgresql_18:
            return self.as_sql(compiler, connection, **extra_context)
        return self.as_sql(
            compiler, connection, function="GEN_RANDOM_UUID", **extra_context
        )

    def as_mysql(self, compiler, connection, **extra_context):
        if not connection.features.supports_uuid4_function:
            if connection.mysql_is_mariadb:
                raise NotSupportedError("UUID4 requires MariaDB version 11.7 or later.")
            raise NotSupportedError("UUID4 is not supported on MySQL.")
        return self.as_sql(compiler, connection, function="UUID_V4", **extra_context)

    def as_oracle(self, compiler, connection, **extra_context):
        if not connection.features.supports_uuid4_function:
            raise NotSupportedError(
                "UUID4 requires Oracle version 23ai/26ai (23.9) or later."
            )
        return self.as_sql(compiler, connection, function="UUID", **extra_context)


class UUID7(Func):
    function = "UUIDV7"
    output_field = UUIDField()

    def __init__(self, shift=None, **extra):
        if shift is None:
            super().__init__(**extra)
        else:
            super().__init__(shift, **extra)

    def as_sql(self, compiler, connection, **extra_context):
        if not connection.features.supports_uuid7_function:
            raise NotSupportedError("UUID7 is not supported on this database backend.")

        if len(self.source_expressions) == 1:
            if not connection.features.supports_uuid7_function_shift:
                msg = (
                    "The shift argument to UUID7 is not supported "
                    "on this database backend."
                )
                raise NotSupportedError(msg)

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

    def as_postgresql(self, compiler, connection, **extra_context):
        if connection.features.supports_uuid7_function:
            return self.as_sql(compiler, connection, **extra_context)
        raise NotSupportedError("UUID7 requires PostgreSQL version 18 or later.")

Review comment (suggestion):
I don't think setting this to `arity = 1` (as suggested in https://github.com/django/django/pull/20101#discussion_r2608226079) makes sense, so I've just removed it again. The problem is that setting `arity = 1` means that `shift` becomes required, rather than optional. I'm open to suggestions if there's something I've missed here.

Code after:

    def as_postgresql(self, compiler, connection, **extra_context):
        if connection.features.is_postgresql_18:
            return self.as_sql(compiler, connection, **extra_context)
        return self.as_sql(
            compiler, connection, function="GEN_RANDOM_UUID", **extra_context
        )

    def as_mysql(self, compiler, connection, **extra_context):
        if not connection.features.supports_uuid4_function:
            if connection.mysql_is_mariadb:
                raise NotSupportedError("UUID4 requires MariaDB version 11.7 or later.")
            raise NotSupportedError("UUID4 is not supported on MySQL.")
        return self.as_sql(compiler, connection, function="UUID_V4", **extra_context)

    def as_oracle(self, compiler, connection, **extra_context):
        if not connection.features.supports_uuid4_function:
            raise NotSupportedError(
                "UUID4 requires Oracle version 23ai/26ai (23.9) or later."
            )
        return self.as_sql(compiler, connection, function="UUID", **extra_context)


class UUID7(Func):
    function = "UUIDV7"
    arity = 1
    output_field = UUIDField()

    def __init__(self, shift=None, **extra):
        super().__init__(shift, **extra)

    def _parse_expressions(self, *expressions):
        if expressions[0] is None:
            expressions = expressions[1:]
        return super()._parse_expressions(*expressions)

    def as_sql(self, compiler, connection, **extra_context):
        if not connection.features.supports_uuid7_function:
            raise NotSupportedError("UUID7 is not supported on this database backend.")

        if len(self.source_expressions) == 1:
            if not connection.features.supports_uuid7_function_shift:
                msg = (
                    "The shift argument to UUID7 is not supported "
                    "on this database backend."
                )
                raise NotSupportedError(msg)

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

    def as_postgresql(self, compiler, connection, **extra_context):