instructure/canvas-lms · error · GraphQL::ExecutionError

no such target context

Error message

no such target context

What it means

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).

Solutions

  1. Verify the targetContextId exists (e.g. GET /api/v1/courses/:id or accounts/:id) before importing
  2. Use a valid course/account ID in the current environment/shard
  3. Refresh any stale ID caches or configuration pointing at the old environment

Example fix

// before
input: { targetContextType: "Course", targetContextId: 999999999 }
// after
input: { targetContextType: "Course", targetContextId: 42 } // verified existing course
Defensive patterns

Strategy: validation

Validate before calling

// pre-check via GraphQL/REST that the context exists and is accessible
const ctx = await client.query({ query: CONTEXT_EXISTS, variables: { id } });
if (!ctx.data?.context) throw new Error(`Target context ${id} not found`);

Try / catch

try {
  await client.mutate({ mutation: IMPORT_OUTCOMES, variables: { input } });
} catch (e) {
  if (e.message.includes('no such target context')) {
    // refresh context list and ask user to re-select
  }
}

Prevention

When it happens

Trigger: Passing a targetContextId for a Course/Account that was deleted, belongs to another shard, or whose ID was mistyped in the importOutcomes mutation.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/9c7a7d1f3b710870. Report an issue: GitHub.

Appendix: source

Thrown at app/graphql/mutations/import_outcomes.rb:343

          "targetContextType required if targetContextId provided"
        )
      elsif input[:target_context_type].present? && input[:target_context_id].blank?
        raise GraphQL::ExecutionError, I18n.t(
          "targetContextId required if targetContextType provided"
        )
      end

      target_context =
        begin
          context_class(input[:target_context_type]).find_by(
            id: input[:target_context_id]
          )
        rescue NameError
          raise GraphQL::ExecutionError, I18n.t("Invalid targetContextType")
        end

      if target_context.nil?
        raise GraphQL::ExecutionError, I18n.t("no such target context")
      end

      [target_context, target_context.root_outcome_group]
    end
  end

  def context_class(context_type)
    raise NameError unless VALID_CONTEXTS.include? context_type

    context_type.constantize
  end

  def process_job(source_context:, target_group:, group: nil, outcome_id: nil)
    target_context = target_group.context
    progress = target_context.progresses.new(tag: "import_outcomes", user: current_user)

    if progress.save
      progress.process_job(

View on GitHub (pinned to 1c9f0bb801)