instructure/canvas-lms · error · ImportError

No role_id or role given for admin

Error message

No role_id or role given for admin

What it means

Raised by SIS::AdminImporter#process_admin when neither `role_id` nor `role` is provided for an admin row. The importer must resolve a concrete role to create the account-user membership, so at least one role identifier is mandatory.

Solutions

  1. Set the `role` column to a known role name (e.g. AccountAdmin) or provide `role_id` for the row.
  2. Look up the role id in the target account (Account.roles / role_overrides) and pass role_id: explicitly.
  3. Add CSV pre-validation requiring exactly one of role or role_id per admin row.

Example fix

// before
process_admin(user_id: 'u1', account_id: 'a1', status: 'active')
// after
process_admin(user_id: 'u1', account_id: 'a1', status: 'active', role: 'AccountAdmin')
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, 'provide role or role_id for admin' if role.blank? && role_id.blank?

Try / catch

begin
  importer.process_admin(user_id:, account_id:, role:, status:)
rescue SIS::ImportError => e
  errors << { row: row_no, message: e.message }
end

Prevention

When it happens

Trigger: process_admin(user_id:, account_id:, status:) called with both role: and role_id: nil/blank; CSV row with empty `role` and `role_id` columns.

Common situations: CSV template missing the role column; exporters that only emit role_id or only role while the importer input has neither; scripts assuming a default admin role is applied automatically.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/449fd72aea591de9. Report an issue: GitHub.

Appendix: source

Thrown at lib/sis/admin_importer.rb:65

                    :account_users_to_update_associations,
                    :account_users_to_set_batch_id

      def initialize(batch, root_account, logger)
        @batch = batch
        @root_account = root_account
        @account = root_account
        @logger = logger
        @success_count = 0
        @roll_back_data = []
        @account_users_to_update_associations = Set.new
        @account_users_to_set_batch_id = Set.new
        @account_roles_by_account_id = {}
      end

      def process_admin(user_id: nil, account_id: nil, role_id: nil, role: nil, status: nil, root_account: nil)
        raise ImportError, "No user_id given for admin" if user_id.blank?
        raise ImportError, "No status given for admin" if status.blank?
        raise ImportError, "No role_id or role given for admin" if role.blank? && role_id.blank?

        state = status.downcase.strip
        raise ImportError, "Invalid status #{status} for admin" unless %w[active deleted].include? state
        return if @batch.skip_deletes? && state == "deleted"

        get_account(account_id)
        raise ImportError, "Invalid account_id given for admin" unless @account

        get_role(role_id, role)
        raise ImportError, "Invalid role '#{role}' for admin" if role.present? && !@role
        raise ImportError, "Invalid role_id '#{role_id}' for admin" if role_id.present? && !@role

        the_root_account = root_account_from_id(root_account) if root_account
        raise ImportError, "Invalid or unknown user_id '#{user_id}' for admin" if root_account && !the_root_account

        the_root_account ||= @root_account

        user = get_user(user_id, the_root_account)

View on GitHub (pinned to 1c9f0bb801)