instructure/canvas-lms · error · Canvas::Migration::Error

Not importing academic benchmark data because no user found…

Error message

Not importing academic benchmark data because no user found matching id '#{user_id}'

What it means

Canvas::Migration::Error raised by AcademicBenchmark.ensure_real_user when User.find_by(id: user_id) returns nil, i.e. no User record exists for the id passed into an academic benchmark standards import. The gem refuses to run the import because every outcome import must be attributed to a real user who can be permission-checked.

Solutions

  1. Verify the user_id passed to the import exists: User.find_by(id: user_id) in the rails console.
  2. Fix the caller to resolve the actual importing user (e.g. from ContentMigration#user) instead of a stale id.
  3. If the user was deleted, re-run the import with a valid site-admin user.
  4. For cross-shard ids, ensure the id is a global id or that the lookup happens on the correct shard.

Example fix

// before
AcademicBenchmark.import(user_id: params[:user_id])
// after
user = User.find_by(id: params[:user_id])
raise ArgumentError, 'user not found' unless user
AcademicBenchmark.import(user_id: user.id)
Defensive patterns

Strategy: validation

Validate before calling

user = User.find_by(id: user_id)
raise ArgumentError, "user #{user_id} not found" unless user
# then call AcademicBenchmark.import(user_id: user.id)

Type guard

valid_user = ->(u) { u.is_a?(User) && u.persisted? }

Try / catch

begin
  AcademicBenchmark.import(user_id: user_id)
rescue Canvas::Migration::Error => e
  Rails.logger.warn("benchmark import aborted: #{e.message}")
end

Prevention

When it happens

Trigger: Calling AcademicBenchmark.import/ensure_real_user with a user_id that is nil, deleted, from another shard, or otherwise not present in the users table.

Common situations: Queued migration jobs referencing a user removed before the job ran; cross-shard user ids not resolvable; tests passing a fabricated id; a content_migration whose user_id setting was never set.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at gems/plugins/academic_benchmark/lib/academic_benchmark.rb:221

  def self.authorized?
    check_for_import_rights(
      user: ensure_real_user(user_id: ensure_user_id_set)
    )
  end

  def self.ensure_user_id_set
    uid = Setting.get("academic_benchmark_migration_user_id", nil)
    unless uid.present?
      raise Canvas::Migration::Error,
            "Not importing academic benchmark data because no user id set"
    end
    uid
  end

  def self.ensure_real_user(user_id:)
    u = User.find_by(id: user_id)
    unless u
      raise Canvas::Migration::Error,
            "Not importing academic benchmark data because no user found matching id '#{user_id}'"
    end
    u
  end

  def self.check_for_import_rights(user:)
    unless Account.site_admin.grants_right?(user, :manage_global_outcomes)
      raise Canvas::Migration::Error,
            "Not importing academic benchmark data because user with ID " \
            "'#{user.id}' isn't allowed to edit global outcomes"
    end
    user
  end
end

View on GitHub (pinned to 1c9f0bb801)