{"record":{"id":"f31eb09e22fae1b2","repo":"instructure/canvas-lms","slug":"invalid-role-id-role-id-for-admin","errorCode":null,"errorMessage":"Invalid role_id '#{role_id}' for admin","messagePattern":"Invalid role_id '#(.+?)' for admin","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/admin_importer.rb","lineNumber":76,"sourceCode":"        @account_users_to_set_batch_id = Set.new\n        @account_roles_by_account_id = {}\n      end\n\n      def process_admin(user_id: nil, account_id: nil, role_id: nil, role: nil, status: nil, root_account: nil)\n        raise ImportError, \"No user_id given for admin\" if user_id.blank?\n        raise ImportError, \"No status given for admin\" if status.blank?\n        raise ImportError, \"No role_id or role given for admin\" if role.blank? && role_id.blank?\n\n        state = status.downcase.strip\n        raise ImportError, \"Invalid status #{status} for admin\" unless %w[active deleted].include? state\n        return if @batch.skip_deletes? && state == \"deleted\"\n\n        get_account(account_id)\n        raise ImportError, \"Invalid account_id given for admin\" unless @account\n\n        get_role(role_id, role)\n        raise ImportError, \"Invalid role '#{role}' for admin\" if role.present? && !@role\n        raise ImportError, \"Invalid role_id '#{role_id}' for admin\" if role_id.present? && !@role\n\n        the_root_account = root_account_from_id(root_account) if root_account\n        raise ImportError, \"Invalid or unknown user_id '#{user_id}' for admin\" if root_account && !the_root_account\n\n        the_root_account ||= @root_account\n\n        user = get_user(user_id, the_root_account)\n        raise ImportError, \"Invalid or unknown user_id '#{user_id}' for admin\" unless user\n\n        if state == \"deleted\" && user.id == @batch&.user_id && @account == @root_account\n          raise ImportError, \"Can't remove yourself user_id '#{user_id}'\"\n        end\n\n        create_or_find_admin(user, state)\n        user.clear_adminable_accounts_cache!\n        @success_count += 1\n      end\n","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/admin_importer.rb#L58-L94","documentation":"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.","triggerScenarios":"role_id: from a different Canvas environment or shard; role_id of a deleted role; role_id belonging to another root account.","commonSituations":"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.","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."],"exampleFix":"// before\nprocess_admin(user_id: 'u1', account_id: 'a1', role_id: 987654, status: 'active')\n// after\nprocess_admin(user_id: 'u1', account_id: 'a1', role_id: 123456, status: 'active') # id from target account","handlingStrategy":"validation","validationCode":"role = Role.find_by(id: role_id)\nraise ArgumentError, \"role_id #{role_id} not found\" unless role","typeGuard":null,"tryCatchPattern":"begin\n  importer.process_admin(user_id:, account_id:, role_id:, status:)\nrescue SIS::ImportError => e\n  errors << { row: row_no, message: e.message }\nend","preventionTips":["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."],"tags":["sis-import","role-lookup","entity-not-found"],"backgroundTag":"record-not-found","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}