{"record":{"id":"c96ae151afe3e1d4","repo":"instructure/canvas-lms","slug":"invalid-course-format-course-format-for-course-course-id","errorCode":null,"errorMessage":"Invalid course_format \"#{course_format}\" for course #{course_id}","messagePattern":"Invalid course_format \"#(.+?)\" for course #(.+?)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/course_importer.rb","lineNumber":70,"sourceCode":"        @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)\n          end","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/course_importer.rb#L52-L88","documentation":"SisCourseImporter#add_course raises ImportError when course_format is non-blank and does not match /\\A(online|on_campus|blended|not_set)/i. course_format is an optional column; if provided it must be one of Canvas's four recognized course formats.","triggerScenarios":"add_course called with course_format like \"web\", \"hybrid\", \"face_to_face\", \"online_course\", or a leading-space value (\\A anchor makes \" online\" fail). Any non-empty value outside the four-option enum triggers it.","commonSituations":"Institutions exporting their own LMS course-delivery labels (hybrid, in-person, web-enhanced) directly into the SIS file; case handled fine (case-insensitive) but synonyms are not; optional column filled with placeholder text like \"TBD\".","solutions":["Map source-system delivery modes to one of online|on_campus|blended|not_set before import","Leave the course_format column blank if the value is unknown — blank is explicitly accepted","Normalize values to lowercase and strip whitespace; remember leading whitespace fails the \\A-anchored match","Pre-validate the CSV: allow only blank or the four enum values"],"exampleFix":"// before\nformat = row[\"delivery\"] # \"hybrid\"\n// after\nformat = {\"hybrid\"=>\"blended\", \"in-person\"=>\"on_campus\", \"web\"=>\"online\"}.fetch(row[\"delivery\"].to_s.strip.downcase, \"not_set\")","handlingStrategy":"validation","validationCode":"fmt = row['course_format'].to_s.strip\nraise ArgumentError, \"bad course_format #{fmt}\" unless fmt.empty? || fmt.downcase.match?(/\\A(online|on_campus|blended|not_set)/)","typeGuard":"def valid_course_format?(f) = f.to_s.strip.empty? || %w[online on_campus blended not_set].any? { |v| f.to_s.strip.downcase.start_with?(v) }","tryCatchPattern":"begin\n  importer.add_course(...)\nrescue SisImport::ImportError => e\n  raise unless e.message.start_with?('Invalid course_format')\n  log.warn(\"normalizing course_format and retrying: #{e.message}\")\nend","preventionTips":["Map institution-specific delivery modes to Canvas's four values at export time","Leave optional enum columns blank when unknown rather than guessing","Normalize case/whitespace for enum columns in the export step","Snapshot valid enum values from Canvas docs when generating files"],"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"}