instructure/canvas-lms · error · ImportError
Invalid role_id '# ' for admin
Error message
Invalid role_id '#{role_id}' for admin What it means
Raised by SIS::AdminImporter#process_admin when a `role_id` was supplied but get_role could not resolve it to an existing role. The numeric/sis role id does not correspond to any role visible to the importer.
Solutions
- Verify the role_id exists in the target root account (Role.where(id: ...)) and correct it.
- Prefer the role name (`role` column) over role_id for cross-environment portability.
- Re-export the roles and regenerate role_ids for the current environment.
Example fix
// before process_admin(user_id: 'u1', account_id: 'a1', role_id: 987654, status: 'active') // after process_admin(user_id: 'u1', account_id: 'a1', role_id: 123456, status: 'active') # id from target account
Defensive patterns
Strategy: validation
Validate before calling
role = Role.find_by(id: role_id)
raise ArgumentError, "role_id #{role_id} not found" unless role Try / catch
begin
importer.process_admin(user_id:, account_id:, role_id:, status:)
rescue SIS::ImportError => e
errors << { row: row_no, message: e.message }
end Prevention
- Regenerate role ids per environment; never reuse ids across prod/beta/test.
- Check for soft-deleted roles when reusing old exports.
- Prefer role names for portable SIS files.
When it happens
Trigger: role_id: from a different Canvas environment or shard; role_id of a deleted role; role_id belonging to another root account.
Common situations: Copying CSVs between prod/beta where role ids differ; ids taken from Role dump of a different shard; role removed by an admin before the admin import ran.
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
- Invalid role '# ' for admin
- Invalid account_id given for admin
- Invalid or unknown user_id '#
- # # didn't exist for # user
- A course did not pass validation
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/f31eb09e22fae1b2.
Report an issue: GitHub.
Appendix: source
Thrown at lib/sis/admin_importer.rb:76
@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)
user.clear_adminable_accounts_cache!
@success_count += 1
end
View on GitHub (pinned to 1c9f0bb801)