instructure/canvas-lms · error · ImportError

Invalid or unknown user_id '#

Error message

Invalid or unknown user_id '#{user_id}' for admin

What it means

First of two identical messages: raised when a `root_account` was supplied but root_account_from_id cannot resolve it, so the importer cannot scope the user lookup. The admin row's root account reference is invalid or unknown.

Solutions

  1. Verify the root_account identifier resolves to an existing root account and correct it.
  2. Remove the root_account argument so the importer's default @root_account (batch root) is used.
  3. Ensure the root account is created/imported before the admin import runs.

Example fix

// before
process_admin(user_id: 'u1', account_id: 'a1', role: 'AccountAdmin', status: 'active', root_account: 'missing-root')
// after
process_admin(user_id: 'u1', account_id: 'a1', role: 'AccountAdmin', status: 'active') # uses batch root account
Defensive patterns

Strategy: validation

Validate before calling

ra = root_account_id && (Account.find_by(id: root_account_id) ||
  Account.find_by(sis_source_id: root_account_id, root_account: true))
raise ArgumentError, 'root_account not found' if root_account_id && !ra&.root_account?

Try / catch

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

Prevention

When it happens

Trigger: process_admin called with root_account: set to an id/sis id that does not resolve to an account; multi-tenant imports referencing a root account that does not exist.

Common situations: Multi-tenant setups where CSVs were generated against a different root account; typo in root_account sis id; root account deleted or not yet imported.

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/43a82ad7eabf5fcf. Report an issue: GitHub.

Appendix: source

Thrown at lib/sis/admin_importer.rb:79

      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)
        user.clear_adminable_accounts_cache!
        @success_count += 1
      end

      def create_or_find_admin(user, state)
        case state
        when "active"

View on GitHub (pinned to 1c9f0bb801)