instructure/canvas-lms · error · RuntimeError

context required

Error message

context required

What it means

RubricAssociation.generate is the factory that creates/updates a rubric association for a course or account context. Canvas raises this RuntimeError when the context argument is nil, since every association must belong to a course/account and permissions are checked against it.

Solutions

  1. Pass the actual context (course or account): RubricAssociation.generate(user, rubric, course, params)
  2. Verify the course/account was loaded successfully before calling generate
  3. Guard the call site with an early return or clearer error when context is blank

Example fix

// before
RubricAssociation.generate(user, rubric, nil, params)
// after
raise "course not found" unless course
RubricAssociation.generate(user, rubric, course, params)
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, "context required" if context.blank?

Type guard

def valid_context?(c) = c.is_a?(Course) || c.is_a?(Account)

Try / catch

begin
  RubricAssociation.generate(user, rubric, context, params)
rescue RuntimeError => e
  raise unless e.message == "context required"
  Rails.logger.error("rubric generation without context")
end

Prevention

When it happens

Trigger: Calling RubricAssociation.generate(current_user, rubric, nil, params) — usually when the course/account lookup returned nil or a variable was not initialized.

Common situations: Controllers using @context that is nil due to routing/context-loading failures; importers or API code creating rubric associations outside a course; scripts with unassigned context variables.

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/bd1b54b1f68d8e67. Report an issue: GitHub.

Appendix: source

Thrown at app/models/rubric_association.rb:255

    assessment_request = assessment_requests.where(user_id: assessee).first
    assessment_request ||= assessment_requests.build(user: assessee)
    assessment_request.send_reminder! if assessment_request.assigned?
    assessment_request
  end

  def update_rubric
    return if skip_updating_rubric_association_count

    rubric.update_association_count
  end
  protected :update_rubric

  def unsubmitted_users
    context.students - rubric_assessments.map(&:user) - assessment_requests.map(&:user)
  end

  def self.generate(current_user, rubric, context, params)
    raise "context required" unless context

    association_object = params.delete :association_object
    if (association_id = params.delete(:id)) && association_id.present?
      association = RubricAssociation.where(id: association_id).first
    end
    association = nil unless association && association.context == context && association.association_object == association_object
    raise "association required" unless association || association_object

    # Update/create the association -- this is what ties the rubric to an entity
    update_if_existing = params.delete(:update_if_existing)
    if params[:hide_points] == "1"
      params[:use_for_grading] = "0"
      params[:hide_score_total] = "0"
    end
    association ||= rubric.associate_with(
      association_object,
      context,
      current_user:,

View on GitHub (pinned to 1c9f0bb801)