def patch_db_connections():
    """
    This wraps django.db.connections._connections with a TaskLocal object.

    The Django transactions are only thread-safe, using threading.local,
    and don't know about coroutines.
    """

    global __already_patched

    if not __already_patched:
        from django.db import connections

        connections._connections = local(connections._connections)
        __already_patched = True
This wraps django.db.connections._connections with a TaskLocal object.

    The Django transactions are only thread-safe, using threading.local,
    and don't know about coroutines.