instructure/canvas-lms · error · GraphQL::ExecutionError
invalid context for group
Error message
invalid context for group
What it means
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.
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
Example fix
# verify association before calling source = LearningOutcomeGroup.active.find(group_id).context target = LearningOutcomeGroup.active.find(target_group_id).context raise "unassociated" unless target.associated_accounts.include?(source) # then run importOutcomes(groupId:, targetGroupId:)
Defensive patterns
Strategy: validation
Validate before calling
// rails console precheck
source = LearningOutcomeGroup.active.find(group_id).context
target = context_for(target_args)
abort("invalid context for group") unless target.associated_accounts.include?(source) Try / catch
try {
await importOutcomes(input);
} catch (e) {
if (e.message === "invalid context for group") {
// choose a source group from an associated account or the global outcomes
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "You do not have permission" / 403 Forbidden errors: authenticated but not allowed — causes and fixes across open-source libraries — this error's family across 31 libraries.
Related errors
- group not found
- insufficient permission
- insufficient permission
- insufficient permission
- insufficient permission
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/dcf6176c83f29e4e.
Report an issue: GitHub.
Appendix: source
Thrown at app/graphql/mutations/import_outcomes.rb:85
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
# verify the outcome is eligible to be linked into the group's context
unless target_context.available_outcome(outcome_id, allow_global: true)
raise GraphQL::ExecutionError, I18n.t(
"Outcome %{outcome_id} is not available in context %{context_type}#%{context_id}",
outcome_id:,View on GitHub (pinned to 1c9f0bb801)