{"record":{"id":"0b702a3615c59a15","repo":"instructure/canvas-lms","slug":"no-user-id-given-for-a-user","errorCode":null,"errorMessage":"No user_id given for a user","messagePattern":"No user_id given for a user","errorType":"validation","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/user_importer.rb","lineNumber":75,"sourceCode":"        @batch = batch\n        @root_account = root_account\n        @logger = logger\n        @batched_users = []\n        @messages = messages\n        @success_count = 0\n\n        @roll_back_data = []\n        @users_to_set_sis_batch_ids = []\n        @pseudos_to_set_sis_batch_ids = []\n        @users_to_add_account_associations = []\n        @users_to_update_account_associations = []\n        @users_to_sync = Set.new\n        @authentication_providers = {}\n      end\n\n      # Pass a single instance of SIS::Models::User\n      def add_user(user, login_only: false)\n        raise ImportError, \"No user_id given for a user\" if user.user_id.blank?\n        raise ImportError, \"No login_id given for user #{user.user_id}\" if user.login_id.blank?\n        raise ImportError, \"No status given for user #{user.user_id}\" if user.status.blank?\n        raise ImportError, \"Improper status for user #{user.user_id}\" unless user.status.match?(/\\A(active|suspended|deleted)/i)\n        return if @batch.skip_deletes? && user.status.match?(/deleted/i)\n\n        if login_only && user.existing_user_id.blank? && user.existing_integration_id.blank? && user.existing_canvas_user_id.blank?\n          raise ImportError, I18n.t(\"No existing user provided for login with SIS ID %{user_id}\", user_id: user.user_id)\n        end\n\n        @batched_users << user\n        process_batch(login_only:) if @batched_users.size >= BATCH_SIZE\n      end\n\n      def any_left_to_process?\n        !@batched_users.empty?\n      end\n\n      def infer_user_name(user_row, prior_name = nil)","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/user_importer.rb#L57-L93","documentation":"SisImporter#add_user validates each SIS::Models::User before batching it for import. The very first check requires a non-blank user_id (the SIS identifier used to match/create the user). If user.user_id is nil or empty, an SisImports::ImportError-style ImportError is raised immediately so the batch is never queued with an unidentifiable record.","triggerScenarios":"Calling importer.add_user(user) with a SIS::Models::User built from a CSV/XML row whose user_id column (or <user_id> element) is blank; constructing Models::User manually and omitting user_id; a parser mapping that drops the user_id field.","commonSituations":"SIS export files with a missing/empty user_id cell; custom integration scripts building user rows by hand; schema drift after SIS export format changes leaving the id column unnamed.","solutions":["Ensure the source record has a user_id before calling add_user: skip or fix rows with a blank user_id","Verify your CSV/XML header or parser maps the id column to Models::User#user_id","Default or derive user_id from a login/email upstream if the export truly lacks it","Wrap add_user calls in error handling so one bad row can be logged and the import continued"],"exampleFix":"// before\nsis_users.each { |u| importer.add_user(u) }\n// after\nsis_users.each do |u|\n  next if u.user_id.blank?\n  importer.add_user(u)\nend","handlingStrategy":"validation","validationCode":"raise 'user_id required' if user.respond_to?(:user_id) && user.user_id.blank?\nimporter.add_user(user) if user.user_id.present?","typeGuard":"def importable_user?(u)\n  u.is_a?(Sis::Models::User) && u.user_id.present?\nend","tryCatchPattern":"begin\n  importer.add_user(user)\nrescue SisImports::ImportError => e\n  Rails.logger.warn(\"skipping user row: #{e.message}\")\nend","preventionTips":["Validate every source row's user_id before building Models::User","Keep CSV/XML headers mapped explicitly to Models::User fields","Unit-test the parser against exports with missing cells"],"tags":["sis","import","validation","ruby"],"backgroundTag":"empty-required-field","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"}