{"record":{"id":"dcf6176c83f29e4e","repo":"instructure/canvas-lms","slug":"invalid-context-for-group","errorCode":null,"errorMessage":"invalid context for group","messagePattern":"invalid context for group","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/import_outcomes.rb","lineNumber":85,"sourceCode":"    verify_authorized_action!(target_context, :manage_outcomes)\n\n    if (group_id = input[:group_id].presence)\n      # Import the entire group into the given context\n      group = LearningOutcomeGroup.active.find_by(id: group_id)\n      if group.nil?\n        raise GraphQL::ExecutionError, I18n.t(\"group not found\")\n      end\n\n      # If optional source context provided, then check that\n      # matches the group's context\n      source_context ||= group.context\n      if source_context && source_context != group.context\n        raise GraphQL::ExecutionError, I18n.t(\"source context does not match group context\")\n      end\n\n      # source has to be global or in an associated account\n      unless !source_context || target_context.associated_accounts.include?(source_context)\n        raise GraphQL::ExecutionError, I18n.t(\"invalid context for group\")\n      end\n\n      # source can't be a root group\n      if group.learning_outcome_group_id.nil?\n        raise GraphQL::ExecutionError, I18n.t(\"cannot import a root group\")\n      end\n\n      return process_job(\n        source_context:, group:, target_group:\n      )\n    elsif (outcome_id = input[:outcome_id].presence)\n      # Import the selected outcome into the given group\n\n      # verify the outcome is eligible to be linked into the group's context\n      unless target_context.available_outcome(outcome_id, allow_global: true)\n        raise GraphQL::ExecutionError, I18n.t(\n          \"Outcome %{outcome_id} is not available in context %{context_type}#%{context_id}\",\n          outcome_id:,","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/import_outcomes.rb#L67-L103","documentation":"ImportOutcomes raises this when the source group's context (explicit or derived from the group) is neither the global site (nil source_context is allowed) nor included in target_context.associated_accounts — i.e. the target account does not have access to the source account's outcomes. Outcome import is only allowed from the global context or accounts associated with the target.","triggerScenarios":"Importing a group from Account A into Account B where B's associated accounts (account chain/trust) do not include A; importing into a Course whose account chain excludes the source account; importing from an unrelated sub-account tree.","commonSituations":"Cross-institution imports without trust/association set up; admin trying to import from a sibling sub-account not in the target's association chain; expectations that any account's outcomes are importable.","solutions":["Import from the target context's own account chain or the global outcomes (sourceContext omitted and global group)","Add the source account to the target's association chain (sub-account hierarchy or trust settings) if policy allows","Import via the root account instead of a course so associated_accounts covers the source","Choose a source group that lives in an associated account"],"exampleFix":"# verify association before calling\nsource = LearningOutcomeGroup.active.find(group_id).context\ntarget = LearningOutcomeGroup.active.find(target_group_id).context\nraise \"unassociated\" unless target.associated_accounts.include?(source)\n# then run importOutcomes(groupId:, targetGroupId:)","handlingStrategy":"validation","validationCode":"// rails console precheck\nsource = LearningOutcomeGroup.active.find(group_id).context\ntarget = context_for(target_args)\nabort(\"invalid context for group\") unless target.associated_accounts.include?(source)","typeGuard":null,"tryCatchPattern":"try {\n  await importOutcomes(input);\n} catch (e) {\n  if (e.message === \"invalid context for group\") {\n    // choose a source group from an associated account or the global outcomes\n  }\n}","preventionTips":["Only offer source groups from the target's associated account chain in the UI","Use global outcomes (allow_global) when cross-account import is needed","Set up account trust/associations before attempting cross-tree imports"],"tags":["graphql","permissions","canvas-lms","outcomes"],"backgroundTag":"insufficient-permissions","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"}