{"record":{"id":"dcea6ff45c4a4235","repo":"instructure/canvas-lms","slug":"no-account-id-given-for-an-account","errorCode":null,"errorMessage":"No account_id given for an account","messagePattern":"No account_id given for an account","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/account_importer.rb","lineNumber":52,"sourceCode":"\n      importer.success_count\n    end\n\n    class Work\n      attr_reader :success_count, :accounts_to_set_sis_batch_ids, :roll_back_data\n\n      def initialize(batch, root_account, logger)\n        @batch = batch\n        @root_account = root_account\n        @accounts_cache = {}\n        @roll_back_data = []\n        @logger = logger\n        @success_count = 0\n        @accounts_to_set_sis_batch_ids = Set.new\n      end\n\n      def add_account(account_id, parent_account_id, status, name, integration_id)\n        raise ImportError, \"No account_id given for an account\" if account_id.blank?\n        return if @batch.skip_deletes? && status =~ /deleted/i\n\n        parent = nil\n        unless parent_account_id.blank?\n          parent = @accounts_cache[parent_account_id]\n          parent ||= @root_account.all_accounts.find_by(sis_source_id: parent_account_id)\n          raise ImportError, \"Parent account didn't exist for #{account_id}\" unless parent\n          raise ImportError, \"Cannot restore sub_account with ID: #{account_id} because parent_account with ID: #{parent_account_id} has been deleted.\" if parent.workflow_state == \"deleted\"\n\n          @accounts_cache[parent.sis_source_id] = parent\n        end\n\n        account = @accounts_cache[account_id]\n        account ||= @root_account.all_accounts.find_by(sis_source_id: account_id)\n        if account.nil?\n          raise ImportError, \"No name given for account #{account_id}, skipping\" if name.blank?\n          raise ImportError, \"Improper status \\\"#{status}\\\" for account #{account_id}, skipping\" unless /\\A(active|deleted)/i.match?(status)\n        end","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/account_importer.rb#L34-L70","documentation":"The SIS account importer requires a non-blank account_id (the SIS source id) for every account row. add_account raises ImportError when account_id is blank because an account without an identifier cannot be looked up or created. This is a fail-fast guard at the top of the method before any parent lookup happens.","triggerScenarios":"Calling AccountImporter::Importer#add_account(nil, parent_id, status, name, integration_id) or with '' / whitespace-only account_id. Also occurs when the SIS accounts CSV has an empty account_id cell.","commonSituations":"Malformed SIS accounts.csv with missing account_id column value; CSV parsing that drops empty fields; generator scripts omitting the id for the root-level row (root account should not be in the SIS file at all).","solutions":["Supply a non-blank account_id for the account row in the SIS CSV.","Remove rows that represent the root account — it is identified by the batch's root_account, not by SIS import.","Verify CSV parsing preserves the account_id column (check header name and delimiter)."],"exampleFix":"// before\nadd_account('', 'parent1', 'active', 'Sub Account', nil)\n// after\nadd_account('sub1', 'parent1', 'active', 'Sub Account', nil)","handlingStrategy":"validation","validationCode":"raise ArgumentError, \"account_id required\" if account_id.to_s.strip.empty?","typeGuard":null,"tryCatchPattern":"begin\n  importer.add_account(account_id, parent_id, status, name, integration_id)\nrescue SIS::BaseImporter::ImportError => e\n  errors << {row: account_id, reason: e.message}\nend","preventionTips":["Never include the root account row in accounts.csv","Validate CSV headers and row completeness before import","Reject blank ids during SIS CSV pre-processing"],"tags":["sis","validation","csv-import"],"backgroundTag":"missing-required-argument","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"}