{"record":{"id":"a1958b96a4e9007e","repo":"instructure/canvas-lms","slug":"course-with-id-course-id-didn-t-exist-for-type-display-sis","errorCode":null,"errorMessage":"Course with id \"#{course_id}\" didn't exist for #{type_display} #{sis_id}","messagePattern":"Course with id \"#(.+?)\" didn't exist for #(.+?) #(.+?)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/group_category_importer.rb","lineNumber":71,"sourceCode":"\n      def find_context(account_id, course_id, sis_id, type_display)\n        context = nil\n        if account_id && course_id\n          raise ImportError, \"Only one context is allowed and both course_id and account_id where provided for #{type_display} #{sis_id}.\"\n        end\n\n        if account_id\n          context = @accounts_cache[account_id]\n          context ||= @root_account.all_accounts.active.find_by(sis_source_id: account_id)\n          raise ImportError, \"Account with id \\\"#{account_id}\\\" didn't exist for #{type_display} #{sis_id}\" unless context\n\n          @accounts_cache[context.sis_source_id] = context\n        end\n\n        if course_id\n          context = @courses_cache[course_id]\n          context ||= @root_account.all_courses.active.find_by(sis_source_id: course_id)\n          raise ImportError, \"Course with id \\\"#{course_id}\\\" didn't exist for #{type_display} #{sis_id}\" unless context\n\n          @courses_cache[context.sis_source_id] = context\n        elsif course_id.nil? && type_display == \"differentiation tag set\"\n          raise ImportError, \"No course_id given for #{type_display} #{sis_id}\"\n        end\n\n        context || @root_account\n      end\n\n      def check_context_movement(category, context, sis_id, type_display)\n        if category && category.groups.active.exists? &&\n           !(context.id == category.context_id && context.class.base_class.name == category.context_type)\n\n          item_type = type_display.include?(\"tag\") ? \"tags\" : \"groups\"\n\n          raise ImportError, \"Cannot move #{type_display} #{sis_id} because it has #{item_type} in it.\"\n        end\n      end","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/group_category_importer.rb#L53-L89","documentation":"find_context looks up a Course by sis_source_id (@root_account.all_courses.active.find_by). When the row's course_id doesn't match an active course under the root account, the importer can't resolve the owning context and raises ImportError.","triggerScenarios":"add_group_category / add_differentiation_tag_set / add_group / add_tag called with a course_id whose sis_source_id does not exist, is soft-deleted, is inactive, or is under a different root account.","commonSituations":"Importing into a fresh/empty Canvas instance before courses were provisioned; course sis_source_id renamed; course concluded/deleted since export; cross-shard or cross-root-account ID mismatch; typos in the CSV.","solutions":["Confirm the course_id equals an active course's sis_source_id under the root account (courses table, workflow_state 'available'/'created').","Run a courses import before the groups/categories import so target courses exist.","Re-export the CSV to pick up renamed or new sis_source_ids.","If the course is concluded/deleted, restore it or drop the row."],"exampleFix":"// before\ngc-1,Math Groups,,COURSE-999,active  # no such course\n// after\ngc-1,Math Groups,,COURSE-42,active","handlingStrategy":"try-catch","validationCode":"unless Course.active.where(root_account_id: root_account.id, sis_source_id: course_id).exists?\n  raise ArgumentError, \"course #{course_id} not found under root account\"\nend","typeGuard":null,"tryCatchPattern":"begin\n  importer.add_tag(sis_id, nil, course_id, name, status)\nrescue SIS::GroupImporter::ImportError => e\n  if e.message =~ /Course with id/ then defer_row(sis_id, e.message)\n  else raise end\nend","preventionTips":["Order imports: courses first, then enrollments/groups/tag sets","Pre-verify course sis_source_ids against the target root account","Watch for concluded/deleted courses — .active lookup excludes them"],"tags":["sis","csv-import","record-lookup","foreign-key"],"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"}