{"record":{"id":"16c4b4fe97654d01","repo":"instructure/canvas-lms","slug":"source-context-does-not-match-group-context","errorCode":null,"errorMessage":"source context does not match group context","messagePattern":"source context does not match group context","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/import_outcomes.rb","lineNumber":80,"sourceCode":"      )\n    end\n\n    target_context, target_group = get_target(input)\n\n    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","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/import_outcomes.rb#L62-L98","documentation":"ImportOutcomes raises this when the optional sourceContext explicitly provided does not equal the context of the group being imported. The mutation derives the authoritative source context from group.context; a supplied source_context that disagrees is rejected to prevent importing from a different account/course than the group belongs to.","triggerScenarios":"Calling importOutcomes with groupId belonging to Account A while passing sourceContextId/sourceContextType pointing to Account B or a Course; passing a stale sourceContext after the group was moved to another account.","commonSituations":"Client caches source context separately from the group; sub-account group imported while root account passed as source; admin UI in one account context operating on a group from another; group migrations changing group.context.","solutions":["Omit sourceContextId/sourceContextType entirely — the mutation defaults to group.context","Ensure the provided source context matches group.context exactly (same type and id)","Re-fetch the group's context via GraphQL before calling","Fix client state so source context is derived from the selected group, not from page-level context"],"exampleFix":"// before (mismatched context)\nimportOutcomes(input: { groupId: \"7\", sourceContextId: \"2\", sourceContextType: \"Account\", targetGroupId: \"5\" })\n// after: let the mutation infer it\nimportOutcomes(input: { groupId: \"7\", targetGroupId: \"5\" });","handlingStrategy":"validation","validationCode":"if (sourceContextId && group.context.id !== sourceContextId) {\n  throw new Error(\"source context does not match group context\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await importOutcomes(input);\n} catch (e) {\n  if (e.message.includes(\"does not match group context\")) {\n    // drop sourceContext fields and retry — mutation will infer group.context\n  }\n}","preventionTips":["Prefer omitting sourceContext entirely; the group's own context is authoritative","Derive source context from the selected group object, not page state","Re-fetch group context after any account/course moves"],"tags":["graphql","validation","conflicting-arguments","canvas-lms"],"backgroundTag":"invalid-argument-value","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"}