{"record":{"id":"7df50c99d32ac5bf","repo":"instructure/canvas-lms","slug":"target-course-course-id-is-not-a-child-of-current-account","errorCode":null,"errorMessage":"Target course %{course_id} is not a child of current account (%{name})","messagePattern":"Target course %(.+?) is not a child of current account \\(%(.+?)\\)","errorType":"validation","errorClass":"InvalidDataError","httpStatus":null,"severity":"error","filePath":"lib/outcomes/import.rb","lineNumber":98,"sourceCode":"        )\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})\",\n          guid: group[:vendor_guid],\n          name: model.context.name\n        )\n      end\n\n      parents = find_parents(group, group_context, model:)\n      raise InvalidDataError, I18n.t(\"An outcome group can only have one parent\") if parents.length > 1","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/outcomes/import.rb#L80-L116","documentation":"When importing with an Account context and a group targets course_id, the found course must be a child of that account (child_context? check). If the course belongs to a different sub-account tree or root account, the import refuses to write into it, naming both the course id and the current account name. This prevents cross-account imports via account-level context.","triggerScenarios":"Account context = root account, but course_id points to a course under an unrelated sub-account not within that account's subtree; or the course belongs to a different root account entirely.","commonSituations":"Migrating outcomes with the wrong (too high or too narrow) account selected; course ids copied from another institution's Canvas; sub-account reorganization moved a course out of the expected account after the CSV was generated.","solutions":["Run the import with the actual parent account (or ancestor) of the target course.","Remove course_id so the group imports into the current account instead.","Move the course under the expected account, or find the course's current account and re-run there.","Verify child_context? logic expectations by checking course.account_chain includes your context."],"exampleFix":"// before\n# context: account id 1 (root), course 99 belongs to sub-account 7\n{ object_type: 'group', course_id: 99 }\n// after\n# run import with account 7 as context, or omit course_id\n{ object_type: 'group' }","handlingStrategy":"validation","validationCode":"course = Course.find_by(id: group[:course_id])\nraise ArgumentError, \"course not under account\" if course && !(course == account || course.account_chain_ids.include?(account.id))","typeGuard":null,"tryCatchPattern":"begin\n  importer.import_group(group)\nrescue Outcomes::Import::InvalidDataError => e\n  Rails.logger.warn(\"course not child of account: #{e.message}\")\nend","preventionTips":["Verify each target course's account chain before import","Run imports at the account that actually owns the courses","Refresh account structure if sub-accounts were reorganized since export"],"tags":["permissions","hierarchy","outcomes-import","account"],"backgroundTag":"permission-denied","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"}