{"record":{"id":"9c7a7d1f3b710870","repo":"instructure/canvas-lms","slug":"no-such-target-context","errorCode":null,"errorMessage":"no such target context","messagePattern":"no such target context","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/import_outcomes.rb","lineNumber":343,"sourceCode":"          \"targetContextType required if targetContextId provided\"\n        )\n      elsif input[:target_context_type].present? && input[:target_context_id].blank?\n        raise GraphQL::ExecutionError, I18n.t(\n          \"targetContextId required if targetContextType provided\"\n        )\n      end\n\n      target_context =\n        begin\n          context_class(input[:target_context_type]).find_by(\n            id: input[:target_context_id]\n          )\n        rescue NameError\n          raise GraphQL::ExecutionError, I18n.t(\"Invalid targetContextType\")\n        end\n\n      if target_context.nil?\n        raise GraphQL::ExecutionError, I18n.t(\"no such target context\")\n      end\n\n      [target_context, target_context.root_outcome_group]\n    end\n  end\n\n  def context_class(context_type)\n    raise NameError unless VALID_CONTEXTS.include? context_type\n\n    context_type.constantize\n  end\n\n  def process_job(source_context:, target_group:, group: nil, outcome_id: nil)\n    target_context = target_group.context\n    progress = target_context.progresses.new(tag: \"import_outcomes\", user: current_user)\n\n    if progress.save\n      progress.process_job(","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/import_outcomes.rb#L325-L361","documentation":"After resolving the context class, get_target does context_class(...).find_by(id: input[:target_context_id]). If no record matches, target_context is nil and the mutation raises this ExecutionError: the requested target context does not exist (or is not visible).","triggerScenarios":"Passing a targetContextId for a Course/Account that was deleted, belongs to another shard, or whose ID was mistyped in the importOutcomes mutation.","commonSituations":"Stale IDs cached in frontend config; cross-shard IDs without the shard prefix in multi-tenant setups; environments cloned from production data with different ID sequences.","solutions":["Verify the targetContextId exists (e.g. GET /api/v1/courses/:id or accounts/:id) before importing","Use a valid course/account ID in the current environment/shard","Refresh any stale ID caches or configuration pointing at the old environment"],"exampleFix":"// before\ninput: { targetContextType: \"Course\", targetContextId: 999999999 }\n// after\ninput: { targetContextType: \"Course\", targetContextId: 42 } // verified existing course","handlingStrategy":"validation","validationCode":"// pre-check via GraphQL/REST that the context exists and is accessible\nconst ctx = await client.query({ query: CONTEXT_EXISTS, variables: { id } });\nif (!ctx.data?.context) throw new Error(`Target context ${id} not found`);","typeGuard":null,"tryCatchPattern":"try {\n  await client.mutate({ mutation: IMPORT_OUTCOMES, variables: { input } });\n} catch (e) {\n  if (e.message.includes('no such target context')) {\n    // refresh context list and ask user to re-select\n  }\n}","preventionTips":["Fetch context IDs from the API rather than hardcoding them","Account for shard prefixes on cross-shard IDs","Re-validate IDs after environment or data changes"],"tags":["graphql","not-found","outcomes","lookup"],"backgroundTag":"resource-not-found","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"}