instructure/canvas-lms · error · InvalidDataError
Course with canvas id
Error message
Course with canvas id %{id} not found What it means
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.
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.
Example fix
// before
{ object_type: 'group', course_id: 'COURSE-101', ... }
// after
{ object_type: 'group', course_id: 12345, ... } Defensive patterns
Strategy: validation
Validate before calling
ids = rows.map { |r| r[:course_id] }.compact.uniq
missing = ids - Course.where(id: ids).pluck(:id)
raise ArgumentError, "unknown course ids: #{missing.inspect}" if missing.any? Type guard
def course_exists?(id) id.present? && Course.exists?(id: id) end
Try / catch
begin
importer.import_group(group)
rescue Outcomes::Import::InvalidDataError => e
failures << {vendor_guid: group[:vendor_guid], error: e.message}
end Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- Group with ID already exists in another unrelated course or…
- Allocation rule not found
- An old_id, '# ', referenced a different # than the…
- An old_id, '# ', referenced a non-existent # and was not…
- An old_integration_id, '#
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/a04480980c104636.
Report an issue: GitHub.
Appendix: source
Thrown at lib/outcomes/import.rb:91
invalid = group.keys.select do |k|
group[k].present? && OBJECT_ONLY_FIELDS.include?(k)
end
if invalid.present?
raise InvalidDataError, I18n.t(
"Invalid fields for a group: %{invalid}",
invalid: invalid.map(&:to_s).inspect
)
end
group_context = context
if group[:course_id].present?
raise InvalidDataError, I18n.t("Cannot import to other courses") unless context.is_a?(Account)
group_context = Course.find_by(id: group[:course_id])
if group_context.nil?
raise InvalidDataError, I18n.t(
"Course with canvas id %{id} not found",
id: group[:course_id]
)
end
unless child_context?(group_context)
raise InvalidDataError, I18n.t(
"Target course %{course_id} is not a child of current account (%{name})",
course_id: group[:course_id],
name: context.name
)
end
end
model = find_prior_group(group, group_context)
unless model.context == group_context
raise InvalidDataError, I18n.t(
"Group with ID %{guid} already exists in another unrelated course or account (%{name})",View on GitHub (pinned to 1c9f0bb801)