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

No account found for context

Error message

No account found for context

What it means

process_user_observer raises this ImportError unless the status argument matches /\A(active|deleted)\z/i. Status is an enum of exactly 'active' or 'deleted' (case-insensitive); any other value — including 'completed', 'inactive', 'Active ', or nil — is rejected before processing.

Solutions

  1. Change status to exactly 'active' or 'deleted' (any casing).
  2. Map your source system's status vocabulary to Canvas's active/deleted enum before import.
  3. Strip whitespace and trim the status column in pre-processing.
  4. If a valid source status has no Canvas equivalent, decide explicitly to skip the row.

Example fix

// before
process_user_observer('OBS009', 'STU001', 'inactive')

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

Strategy: validation

Validate before calling

raise 'status must be active or deleted' unless %w[active deleted].include?(status.to_s.downcase)

Type guard

def valid_status?(s) = /\A(active|deleted)\z/i.match?(s.to_s)

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 with status = 'inactive', 'enrolled', empty string, or a value with stray whitespace/trailing characters so the strict \A...\z regex fails.

Common situations: CSV exports from other LMS/SIS systems using different status vocabularies; hand-edited rows with typos like 'actve'; scripts passing symbols or objects that interpolate into unexpected strings.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at app/controllers/application_controller.rb:3171

  end

  def resolve_context_account(allow_user_root_account: false)
    case @context
    when Account
      @context
    when Course, Group
      @context.account
    when User
      if allow_user_root_account
        @context.account.root_account
      else
        raise "Account can't be derived from a User context"
      end
    when CourseSection
      @context.course.account
    else
      account = @context.try(:account)
      raise ActiveRecord::RecordNotFound, "No account found for context" unless account.present?

      account
    end
  end

  private :resolve_context_account

  def set_site_admin_context
    @context = Account.site_admin
    add_crumb t("#crumbs.site_admin", "Site Admin"), url_for(Account.site_admin)
  end

  def flash_notices
    @notices ||= begin
      notices = []
      if !browser_supported? && !@embedded_view && !cookies["unsupported_browser_dismissed"]
        notices << { type: "warning", content: { html: unsupported_browser }, classes: "unsupported_browser" }
      end

View on GitHub (pinned to 1c9f0bb801)