from django.db import connections


def share_rows(model, ids, using="default"):
    """Protect RBAC dependencies without exclusive company-level locks."""
    ids = sorted({pk for pk in ids if pk is not None}, key=str)
    if not ids:
        return
    connection = connections[using]
    table = connection.ops.quote_name(model._meta.db_table)
    with connection.cursor() as cursor:
        cursor.execute(f"SELECT id FROM {table} WHERE id = ANY(%s) ORDER BY id FOR SHARE", [ids])
        cursor.fetchall()
