instructure/canvas-lms · error · GraphQL::ExecutionError
source context does not match group context
Error message
source context does not match group context
What it means
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.
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
Example fix
// before (mismatched context)
importOutcomes(input: { groupId: "7", sourceContextId: "2", sourceContextType: "Account", targetGroupId: "5" })
// after: let the mutation infer it
importOutcomes(input: { groupId: "7", targetGroupId: "5" }); Defensive patterns
Strategy: validation
Validate before calling
if (sourceContextId && group.context.id !== sourceContextId) {
throw new Error("source context does not match group context");
} Try / catch
try {
await importOutcomes(input);
} catch (e) {
if (e.message.includes("does not match group context")) {
// drop sourceContext fields and retry — mutation will infer group.context
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Auto-grading failed due to the following issue(s): #
- cannot import a root group
- Invalid context type
- Invalid section ids
- Outcome is not available in context #
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/16c4b4fe97654d01.
Report an issue: GitHub.
Appendix: source
Thrown at app/graphql/mutations/import_outcomes.rb:80
)
end
target_context, target_group = get_target(input)
verify_authorized_action!(target_context, :manage_outcomes)
if (group_id = input[:group_id].presence)
# Import the entire group into the given context
group = LearningOutcomeGroup.active.find_by(id: group_id)
if group.nil?
raise GraphQL::ExecutionError, I18n.t("group not found")
end
# If optional source context provided, then check that
# matches the group's context
source_context ||= group.context
if source_context && source_context != group.context
raise GraphQL::ExecutionError, I18n.t("source context does not match group context")
end
# source has to be global or in an associated account
unless !source_context || target_context.associated_accounts.include?(source_context)
raise GraphQL::ExecutionError, I18n.t("invalid context for group")
end
# source can't be a root group
if group.learning_outcome_group_id.nil?
raise GraphQL::ExecutionError, I18n.t("cannot import a root group")
end
return process_job(
source_context:, group:, target_group:
)
elsif (outcome_id = input[:outcome_id].presence)
# Import the selected outcome into the given group
View on GitHub (pinned to 1c9f0bb801)