instructure/canvas-lms · error · RuntimeError

association required

Error message

association required

What it means

RubricAssociation.generate requires either an existing association (matched by id, context, and association_object) or a new association_object to attach the rubric to. Canvas raises this RuntimeError when neither is supplied, so there is nothing to create or update an association for.

Solutions

  1. Pass params[:association_object] (the assignment, quiz, etc.) when creating a new association
  2. Pass a valid params[:id] whose association matches the given context and association_object
  3. Fix callers that delete/strip :association_object from params before generate

Example fix

// before
RubricAssociation.generate(user, rubric, course, { hide_points: "0" })
// after
RubricAssociation.generate(user, rubric, course, params.merge(association_object: assignment))
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError unless params[:association_object].present? || params[:id].present?

Type guard

def has_association_target?(params) = params[:association_object].present? || params[:id].present?

Try / catch

begin
  RubricAssociation.generate(user, rubric, context, params)
rescue RuntimeError => e
  raise unless e.message == "association required"
  respond_with_missing_association
end

Prevention

When it happens

Trigger: Calling generate with no :id/:association_id in params AND no :association_object in params; or the id-based lookup failed the context/association_object match check and association_object was also nil.

Common situations: API/controller calls omitting association_object or the association id; passing an :id belonging to a different context so the lookup is discarded; importers that drop the association_object param.

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

Appendix: source

Thrown at app/models/rubric_association.rb:262

    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:,
      use_for_grading: params[:use_for_grading] == "1",
      purpose: params[:purpose],
      update_if_existing:
    )
    association.rubric = rubric
    if association.rubric_id_changed? && association_object.is_a?(Assignment)
      association_object.mark_downstream_changes(["rubric"])

View on GitHub (pinned to 1c9f0bb801)