instructure/canvas-lms · error · ImportError
Course with id "# " didn't exist for # #
Error message
Course with id "#{course_id}" didn't exist for #{type_display} #{sis_id} What it means
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.
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.
Example fix
// before gc-1,Math Groups,,COURSE-999,active # no such course // after gc-1,Math Groups,,COURSE-42,active
Defensive patterns
Strategy: try-catch
Validate before calling
unless Course.active.where(root_account_id: root_account.id, sis_source_id: course_id).exists?
raise ArgumentError, "course #{course_id} not found under root account"
end Try / catch
begin importer.add_tag(sis_id, nil, course_id, name, status) rescue SIS::GroupImporter::ImportError => e if e.message =~ /Course with id/ then defer_row(sis_id, e.message) else raise end end
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- Account with id "# " didn't exist for # #
- Parent account didn't exist for #
- A # did not pass validation (# : # , error: # )
- Cannot move # # because it has # in it.
- Cannot restore sub_account with ID: #
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/a1958b96a4e9007e.
Report an issue: GitHub.
Appendix: source
Thrown at lib/sis/group_category_importer.rb:71
def find_context(account_id, course_id, sis_id, type_display)
context = nil
if account_id && course_id
raise ImportError, "Only one context is allowed and both course_id and account_id where provided for #{type_display} #{sis_id}."
end
if account_id
context = @accounts_cache[account_id]
context ||= @root_account.all_accounts.active.find_by(sis_source_id: account_id)
raise ImportError, "Account with id \"#{account_id}\" didn't exist for #{type_display} #{sis_id}" unless context
@accounts_cache[context.sis_source_id] = context
end
if course_id
context = @courses_cache[course_id]
context ||= @root_account.all_courses.active.find_by(sis_source_id: course_id)
raise ImportError, "Course with id \"#{course_id}\" didn't exist for #{type_display} #{sis_id}" unless context
@courses_cache[context.sis_source_id] = context
elsif course_id.nil? && type_display == "differentiation tag set"
raise ImportError, "No course_id given for #{type_display} #{sis_id}"
end
context || @root_account
end
def check_context_movement(category, context, sis_id, type_display)
if category && category.groups.active.exists? &&
!(context.id == category.context_id && context.class.base_class.name == category.context_type)
item_type = type_display.include?("tag") ? "tags" : "groups"
raise ImportError, "Cannot move #{type_display} #{sis_id} because it has #{item_type} in it."
end
endView on GitHub (pinned to 1c9f0bb801)