{"record":{"id":"a04480980c104636","repo":"instructure/canvas-lms","slug":"course-with-canvas-id-id-not-found","errorCode":null,"errorMessage":"Course with canvas id %{id} not found","messagePattern":"Course with canvas id %(.+?) not found","errorType":"validation","errorClass":"InvalidDataError","httpStatus":null,"severity":"error","filePath":"lib/outcomes/import.rb","lineNumber":91,"sourceCode":"      invalid = group.keys.select do |k|\n        group[k].present? && OBJECT_ONLY_FIELDS.include?(k)\n      end\n      if invalid.present?\n        raise InvalidDataError, I18n.t(\n          \"Invalid fields for a group: %{invalid}\",\n          invalid: invalid.map(&:to_s).inspect\n        )\n      end\n\n      group_context = context\n\n      if group[:course_id].present?\n        raise InvalidDataError, I18n.t(\"Cannot import to other courses\") unless context.is_a?(Account)\n\n        group_context = Course.find_by(id: group[:course_id])\n\n        if group_context.nil?\n          raise InvalidDataError, I18n.t(\n            \"Course with canvas id %{id} not found\",\n            id: group[:course_id]\n          )\n        end\n\n        unless child_context?(group_context)\n          raise InvalidDataError, I18n.t(\n            \"Target course %{course_id} is not a child of current account (%{name})\",\n            course_id: group[:course_id],\n            name: context.name\n          )\n        end\n      end\n\n      model = find_prior_group(group, group_context)\n      unless model.context == group_context\n        raise InvalidDataError, I18n.t(\n          \"Group with ID %{guid} already exists in another unrelated course or account (%{name})\",","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/outcomes/import.rb#L73-L109","documentation":"If a group specifies course_id and the import context is an Account, the importer looks up Course.find_by(id: course_id). When no course with that Canvas numeric id exists, this error is raised. Note it matches on Canvas internal id, not SIS id or other identifiers.","triggerScenarios":"group[:course_id] holds an id for a course that was deleted, belongs to a different shard, is an SIS id (e.g. 'COURSE-101') instead of a numeric canvas id, or was simply mistyped.","commonSituations":"Copying course ids from a URL that shows a different id form; cross-shard references that find_by(id:) does not resolve; staging data referencing courses that were purged in production; CSVs exported before courses were deleted.","solutions":["Verify course_id is the numeric Canvas course id (Course.find(id) in console) and not an SIS id.","Look up the course by SIS id instead and translate: Course.find_by(sis_source_id: ...) to get its canvas id.","Remove or blank the course_id so the group imports into the current account context.","Check that the course exists on the same shard/account the import runs against."],"exampleFix":"// before\n{ object_type: 'group', course_id: 'COURSE-101', ... }\n// after\n{ object_type: 'group', course_id: 12345, ... }","handlingStrategy":"validation","validationCode":"ids = rows.map { |r| r[:course_id] }.compact.uniq\nmissing = ids - Course.where(id: ids).pluck(:id)\nraise ArgumentError, \"unknown course ids: #{missing.inspect}\" if missing.any?","typeGuard":"def course_exists?(id)\n  id.present? && Course.exists?(id: id)\nend","tryCatchPattern":"begin\n  importer.import_group(group)\nrescue Outcomes::Import::InvalidDataError => e\n  failures << {vendor_guid: group[:vendor_guid], error: e.message}\nend","preventionTips":["Preflight all course_ids against the DB before import","Use canvas numeric ids, not SIS ids, in course_id","Re-export id lists close to import time — courses get deleted"],"tags":["not-found","database","outcomes-import","identifier"],"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"}