instructure/canvas-lms · error · GraphQL::ExecutionError
no such source context
Error message
no such source context
What it means
ImportOutcomes mutation raises this when sourceContextType/sourceContextId were provided, the type is valid (Account or Course), but no active record with that id exists. The mutation requires the source context to be a real Account or Course before importing outcomes from it.
Solutions
- Verify the sourceContextId exists via GraphQL node query or rails console (Account.find / Course.find)
- Ensure id format matches expectations (legacy numeric vs relay global id)
- Check you are querying the correct shard/root account for the id
- Confirm the Account/Course was not deleted; pick an existing source context
Example fix
// before
importOutcomes(input: { sourceContextId: "999999", sourceContextType: "Course", targetGroupId: "5", groupId: "3" })
// after: verify first
const ctx = await node({ id: toGlobalId("Course", "999999") }); // must not be null
importOutcomes(input: { sourceContextId: "1234", sourceContextType: "Course", targetGroupId: "5", groupId: "3" }); Defensive patterns
Strategy: validation
Validate before calling
const node = await graphqlClient.node(toGlobalId(sourceContextType, sourceContextId));
if (!node) throw new Error(`source context ${sourceContextType}#${sourceContextId} does not exist`); Type guard
const isSourceContext = (n) => n && ["Account", "Course"].includes(n.__typename);
Try / catch
try {
await importOutcomes(input);
} catch (e) {
if (e.message === "no such source context") {
// re-resolve source context id or omit sourceContext to let the group define it
}
} Prevention
- Omit sourceContextId/sourceContextType unless you specifically need to assert it — it is optional
- Resolve ids via GraphQL node lookups, not cached/dumped values
- Mind cross-shard global id formats
- Confirm the Account/Course is not deleted before importing
When it happens
Trigger: Calling importOutcomes with sourceContextType:'Account' or 'Course' plus a sourceContextId that matches no record — deleted account/course, wrong shard id, id from another environment, or a numeric legacy id where a global relay id is needed (or vice versa).
Common situations: Copying requests between prod/staging; referencing a course deleted via course cleanup jobs; cross-shard ids without the proper shard-scoped global id; typos in the id; sourceContextId of a User or other non-Account/Course type.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- group not found
- no such target group
- invalid context for group
- Outcome is not available in context #
- Outcome is not available in context #
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/0ac1ffc8f2706ac8.
Report an issue: GitHub.
Appendix: source
Thrown at app/graphql/mutations/import_outcomes.rb:50
field :progress, Types::ProgressType, null: true
VALID_CONTEXTS = %w[Account Course].freeze
def resolve(input:)
source_context = nil
if input[:source_context_type].present?
if input[:source_context_id].present?
begin
source_context = context_class(input[:source_context_type]).find_by(id: input[:source_context_id])
rescue NameError
return validation_error(
I18n.t("invalid value"), attribute: "sourceContextType"
)
end
if source_context.nil?
raise GraphQL::ExecutionError, I18n.t("no such source context")
end
else
return validation_error(
I18n.t("sourceContextId required if sourceContextType provided"),
attribute: "sourceContextId"
)
end
elsif input[:source_context_id].present?
return validation_error(
I18n.t("sourceContextType required if sourceContextId provided"),
attribute: "sourceContextType"
)
end
target_context, target_group = get_target(input)
verify_authorized_action!(target_context, :manage_outcomes)
View on GitHub (pinned to 1c9f0bb801)