{"record":{"id":"06f1cd3e23a868ef","repo":"instructure/canvas-lms","slug":"invalid-account-id-given-for-admin","errorCode":null,"errorMessage":"Invalid account_id given for admin","messagePattern":"Invalid account_id given for admin","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/admin_importer.rb","lineNumber":72,"sourceCode":"        @logger = logger\n        @success_count = 0\n        @roll_back_data = []\n        @account_users_to_update_associations = Set.new\n        @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)","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/admin_importer.rb#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the account_id exists: check it in the Rails console (Account.find_by(sis_source_id: ...)).","Import the accounts CSV before the admins CSV so referenced accounts exist.","Fix the account_id/sis id in the CSV, or use the correct root_account context."],"exampleFix":"// before\nprocess_admin(user_id: 'u1', account_id: 'acct-xyz', role: 'AccountAdmin', status: 'active')\n// after\nprocess_admin(user_id: 'u1', account_id: 'SUBACCOUNT-101', role: 'AccountAdmin', status: 'active') # id verified to exist","handlingStrategy":"validation","validationCode":"account = account_id.to_s.start_with?('sis:') ?\n  root_account.all_accounts.find_by(sis_source_id: account_id.sub('sis:', '')) :\n  Account.find_by(id: account_id)\nraise ArgumentError, \"account #{account_id} not found\" unless account","typeGuard":null,"tryCatchPattern":"begin\n  importer.process_admin(user_id:, account_id:, role:, status:)\nrescue SIS::ImportError => e\n  errors << { row: row_no, message: e.message }\nend","preventionTips":["Import accounts before admins in the SIS dependency order.","Generate account ids from the same environment the import runs in.","Spot-check referenced account sis ids in the console before bulk import."],"tags":["sis-import","entity-not-found","csv-validation"],"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"}