{"record":{"id":"07c5529ce565419d","repo":"instructure/canvas-lms","slug":"enrollment-enrollment-id-doesn-t-exist","errorCode":null,"errorMessage":"Enrollment #{enrollment_id} doesn't exist","messagePattern":"Enrollment #(.+?) doesn't exist","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/grade_publishing_results_importer.rb","lineNumber":48,"sourceCode":"      attr_accessor :success_count\n\n      def initialize(batch, root_account, logger)\n        @batch = batch\n        @root_account = root_account\n        @logger = logger\n        @success_count = 0\n      end\n\n      def add_grade_publishing_result(enrollment_id, grade_publishing_status, message = nil)\n        raise ImportError, \"No enrollment_id given\" if enrollment_id.blank?\n        raise ImportError, \"No grade_publishing_status given for enrollment #{enrollment_id}\" if grade_publishing_status.blank?\n        raise ImportError, \"Improper grade_publishing_status \\\"#{grade_publishing_status}\\\" for enrollment #{enrollment_id}\" unless %w[published error].include?(grade_publishing_status.downcase)\n\n        if Enrollment.where(id: enrollment_id, root_account_id: @root_account)\n                     .update_all(grade_publishing_status: grade_publishing_status.downcase,\n                                 grade_publishing_message: message.to_s,\n                                 updated_at: Time.now.utc) != 1\n          raise ImportError, \"Enrollment #{enrollment_id} doesn't exist\"\n        end\n\n        @success_count += 1\n      end\n    end\n  end\nend\n","sourceCodeStart":30,"sourceCodeEnd":56,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/grade_publishing_results_importer.rb#L30-L56","documentation":"After validating inputs, add_grade_publishing_result performs `Enrollment.where(id: enrollment_id, root_account_id: @root_account).update_all(...)` and raises ImportError when the affected row count is not exactly 1, meaning no enrollment with that id exists on this root account.","triggerScenarios":"Calling add_grade_publishing_result with an id that is not an existing Enrollment primary key, or an id belonging to a different root account than the one the importer was initialized with; stale/foreign enrollment ids from a previous or other-account import.","commonSituations":"CSV generated against a different Canvas account/shard; enrollment deleted between export and import; ids taken from sis ids instead of numeric Enrollment ids; test data referencing nonexistent enrollments.","solutions":["Verify the enrollment_id values are actual Enrollment#id values on the target root account","Re-export the grade publishing results from the same account as the import target","Filter the CSV against existing Enrollment ids before import: `Enrollment.where(id: ids).pluck(:id)`","Check for cross-shard/account id mixing"],"exampleFix":"// before\nimporter.add_grade_publishing_result(row['sis_enrollment_id'], status)\n// after\nenrollment = Enrollment.where(sis_source_id: row['sis_enrollment_id'], root_account_id: account).first\nimporter.add_grade_publishing_result(enrollment.id, status) if enrollment","handlingStrategy":"validation","validationCode":"valid_ids = Enrollment.where(id: ids, root_account_id: account).pluck(:id)\nids.each { |i| importer.add_grade_publishing_result(i, status) if valid_ids.include?(i) }","typeGuard":null,"tryCatchPattern":"begin\n  importer.add_grade_publishing_result(id, status)\nrescue SIS::Base::ImportError => e\n  logger.warn(\"Enrollment missing: #{e.message}\")\nend","preventionTips":["Preflight-check all enrollment ids against the target account","Never mix sis ids with numeric Enrollment ids","Re-export from the same account/shard as the import target"],"tags":["ruby","sis-import","grade-publishing","record-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"}