instructure/canvas-lms · error · ImportError

Invalid account_id given for admin

Error message

Invalid account_id given for admin

What it means

Raised after get_account resolves the provided `account_id` and the importer finds no matching account (@account is nil). The admin row references an account (by sis id or canvas id) that does not exist under the root account being imported.

Solutions

  1. Verify the account_id exists: check it in the Rails console (Account.find_by(sis_source_id: ...)).
  2. Import the accounts CSV before the admins CSV so referenced accounts exist.
  3. Fix the account_id/sis id in the CSV, or use the correct root_account context.

Example fix

// before
process_admin(user_id: 'u1', account_id: 'acct-xyz', role: 'AccountAdmin', status: 'active')
// after
process_admin(user_id: 'u1', account_id: 'SUBACCOUNT-101', role: 'AccountAdmin', status: 'active') # id verified to exist
Defensive patterns

Strategy: validation

Validate before calling

account = account_id.to_s.start_with?('sis:') ?
  root_account.all_accounts.find_by(sis_source_id: account_id.sub('sis:', '')) :
  Account.find_by(id: account_id)
raise ArgumentError, "account #{account_id} not found" unless account

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 called with account_id: that matches no account in the batch's root account; CSV `account_id` containing an sis id not yet imported or a Canvas id from another instance.

Common situations: Importing admins before the account hierarchy CSV was imported; cross-environment copies (prod ids used in beta/test); typos or changed sis_id formats; account deleted since data export.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at lib/sis/admin_importer.rb:72

        @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)
        raise ImportError, "Invalid or unknown user_id '#{user_id}' for admin" unless user

        if state == "deleted" && user.id == @batch&.user_id && @account == @root_account
          raise ImportError, "Can't remove yourself user_id '#{user_id}'"
        end

        create_or_find_admin(user, state)

View on GitHub (pinned to 1c9f0bb801)