{"record":{"id":"37468757ac8d7a5c","repo":"instructure/canvas-lms","slug":"improper-status-status-for-course-course-id","errorCode":null,"errorMessage":"Improper status \"#{status}\" for course #{course_id}","messagePattern":"Improper status \"#(.+?)\" for course #(.+?)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/course_importer.rb","lineNumber":69,"sourceCode":"      def initialize(batch, root_account, logger, a1, a2, m, batch_user, blueprint_associations)\n        @batch = batch\n        @batch_user = batch_user\n        @root_account = root_account\n        @courses_to_update_sis_batch_id = a1\n        @course_ids_to_update_associations = a2\n        @roll_back_data = []\n        @blueprint_associations = blueprint_associations\n        @messages = m\n        @logger = logger\n        @success_count = 0\n      end\n\n      def add_course(course_id, term_id, account_id, fallback_account_id, status, start_date, end_date, abstract_course_id, short_name, long_name, integration_id, course_format, blueprint_course_id, grade_passback_setting, homeroom_course, friendly_name)\n        state_changes = []\n        raise ImportError, \"No course_id given for a course\" if course_id.blank?\n        raise ImportError, \"No short_name given for course #{course_id}\" if short_name.blank? && abstract_course_id.blank?\n        raise ImportError, \"No long_name given for course #{course_id}\" if long_name.blank? && abstract_course_id.blank?\n        raise ImportError, \"Improper status \\\"#{status}\\\" for course #{course_id}\" unless /\\A(active|deleted|completed|unpublished|published)/i.match?(status)\n        raise ImportError, \"Invalid course_format \\\"#{course_format}\\\" for course #{course_id}\" unless course_format.blank? || course_format =~ /\\A(online|on_campus|blended|not_set)/i\n\n        valid_grade_passback_settings = %w[nightly_sync disabled not_set]\n        raise ImportError, \"Invalid grade_passback_setting \\\"#{grade_passback_setting}\\\" for course #{course_id}\" unless grade_passback_setting.blank? || valid_grade_passback_settings.include?(grade_passback_setting.downcase.strip)\n        return if @batch.skip_deletes? && status =~ /deleted/i\n\n        Course.unique_constraint_retry do\n          course = @root_account.all_courses.find_by(sis_source_id: course_id)\n          if course.nil?\n            course = Course.new\n            state_changes << :created\n          else\n            state_changes << :updated\n          end\n          course.saved_by = :sis_import\n          course_enrollment_term_id_stuck = course.stuck_sis_fields.include?(:enrollment_term_id)\n          if !course_enrollment_term_id_stuck && term_id\n            term = @root_account.enrollment_terms.active.find_by(sis_source_id: term_id)","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/course_importer.rb#L51-L87","documentation":"SisCourseImporter#add_course raises ImportError when the status value does not match /\\A(active|deleted|completed|unpublished|published)/i. SIS course rows must declare a recognized workflow state; any other string is rejected before touching the database.","triggerScenarios":"add_course called with status set to anything outside {active, deleted, completed, unpublished, published} (case-insensitive, prefix match): e.g. \"deleted\", \"Active ×3 typo” like \"actve\", \"enable\", \"pending\", numeric 1/0 passed as \"1\", or a nil status.","commonSituations":"Data teams mapping their SIS statuses to Canvas incorrectly (e.g. \"inactive\", \"archived\", \"closed\"); exports emitting booleans or numeric codes; locale-mutated column values; extra whitespace at the START (leading space breaks the \\A anchor even though trailing text is allowed).","solutions":["Map the source system's status to one of active|deleted|completed|unpublished|published in the CSV export","Strip leading whitespace from the status column (the regex anchors at \\A, so \" active\" fails)","Convert boolean/numeric exports (1/0, true/false) explicitly to \"active\"/\"deleted\"","Add a schema check on the courses.csv before import that validates status against the allowed enum"],"exampleFix":"// before\nstatus = row[\"state\"] # \"inactive\"\n// after\nstatus = {\"inactive\"=>\"deleted\", \"open\"=>\"active\", \"closed\"=>\"completed\"}.fetch(row[\"state\"], row[\"state\"]).to_s.strip","handlingStrategy":"validation","validationCode":"VALID_COURSE_STATUSES = %w[active deleted completed unpublished published]\nstatus = row['status'].to_s.strip\nraise ArgumentError, \"bad status #{status}\" unless VALID_COURSE_STATUSES.any? { |s| status.downcase.start_with?(s) }","typeGuard":"def valid_course_status?(s) = %w[active deleted completed unpublished published].any? { |v| s.to_s.strip.downcase.start_with?(v) }","tryCatchPattern":"begin\n  importer.add_course(...)\nrescue SisImport::ImportError => e\n  raise unless e.message.start_with?('Improper status')\n  log.error(\"unmapped course status in feed: #{e.message}\")\nend","preventionTips":["Maintain an explicit status mapping table between your SIS and Canvas enums","Strip leading/trailing whitespace on enum columns before import","Never emit booleans or numeric codes for status columns","Unit-test the export against the Canvas status regex"],"tags":["sis-import","invalid-enum","course-import"],"backgroundTag":"invalid-enum-value","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"}