instructure/canvas-lms · error · ActiveRecord::RecordNotFound

Context is required, but none found

Error message

Context is required, but none found

What it means

process_user_observer raises this ImportError when the student_id argument (the user being observed) is blank. Without a student SIS ID the importer cannot look up the target user's pseudonym, so the row is rejected before any DB access. This is the counterpart required-argument guard to the observer_id check on the previous line.

Solutions

  1. Supply the student's non-blank SIS user_id in the row or call.
  2. Validate required columns (observer_id, user_id, status) before running the SIS import.
  3. Drop rows missing user_id and re-run the batch for corrected data.

Example fix

// before
process_user_observer('OBS009', nil, 'active')

// after
process_user_observer('OBS009', 'STU001', 'active')
Defensive patterns

Strategy: validation

Validate before calling

raise 'student_id required' if student_id.nil? || student_id.to_s.strip.empty?

Type guard

def blank?(v) = v.nil? || v.to_s.strip.empty?

Try / catch

begin
  importer.process_user_observer(obs_id, stu_id, status)
rescue SIS::Import::ImportError => e
  logger.warn("skipped row: #{e.message}")
end

Prevention

When it happens

Trigger: Calling process_user_observer(observer_id, nil, status) or with an empty-string student_id — typically a users_observers CSV row with a populated observer_id but an empty user_id cell.

Common situations: CSV where user_id column was truncated or misnamed during export; scripts that pass nil because the student SIS ID was not yet provisioned; column-order assumptions after a template change.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — 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/81905bccb2c8f622. Report an issue: GitHub.

Appendix: source

Thrown at app/controllers/application_controller.rb:1457

      end
    end
    set_no_cache_headers
  end

  # To be used as a before_action, requires controller or controller actions
  # to have their urls scoped to a context in order to be valid.
  # So /courses/5/assignments or groups/1/assignments would be valid, but
  # not /assignments
  def require_context(user_scope: nil)
    get_context(user_scope:)
    unless @context
      if @context_is_current_user
        store_location
        redirect_to login_url
      elsif params[:context_id]
        raise ActiveRecord::RecordNotFound, "Cannot find #{params[:context_type] || "Context"} for ID: #{params[:context_id]}"
      else
        raise ActiveRecord::RecordNotFound, "Context is required, but none found"
      end
    end
    !@context.nil?
  end

  def require_context_and_read_access
    require_context && authorized_action(@context, @current_user, :read)
  end

  helper_method :clean_return_to

  def require_account_context
    require_context_type(Account)
  end

  def require_course_context
    require_context_type(Course)
  end

View on GitHub (pinned to 1c9f0bb801)