{"record":{"id":"98e8042f35413a34","repo":"instructure/canvas-lms","slug":"association-required","errorCode":null,"errorMessage":"association required","messagePattern":"association required","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"app/models/rubric_association.rb","lineNumber":262,"sourceCode":"    return if skip_updating_rubric_association_count\n\n    rubric.update_association_count\n  end\n  protected :update_rubric\n\n  def unsubmitted_users\n    context.students - rubric_assessments.map(&:user) - assessment_requests.map(&:user)\n  end\n\n  def self.generate(current_user, rubric, context, params)\n    raise \"context required\" unless context\n\n    association_object = params.delete :association_object\n    if (association_id = params.delete(:id)) && association_id.present?\n      association = RubricAssociation.where(id: association_id).first\n    end\n    association = nil unless association && association.context == context && association.association_object == association_object\n    raise \"association required\" unless association || association_object\n\n    # Update/create the association -- this is what ties the rubric to an entity\n    update_if_existing = params.delete(:update_if_existing)\n    if params[:hide_points] == \"1\"\n      params[:use_for_grading] = \"0\"\n      params[:hide_score_total] = \"0\"\n    end\n    association ||= rubric.associate_with(\n      association_object,\n      context,\n      current_user:,\n      use_for_grading: params[:use_for_grading] == \"1\",\n      purpose: params[:purpose],\n      update_if_existing:\n    )\n    association.rubric = rubric\n    if association.rubric_id_changed? && association_object.is_a?(Assignment)\n      association_object.mark_downstream_changes([\"rubric\"])","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/rubric_association.rb#L244-L280","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass params[:association_object] (the assignment, quiz, etc.) when creating a new association","Pass a valid params[:id] whose association matches the given context and association_object","Fix callers that delete/strip :association_object from params before generate"],"exampleFix":"// before\nRubricAssociation.generate(user, rubric, course, { hide_points: \"0\" })\n// after\nRubricAssociation.generate(user, rubric, course, params.merge(association_object: assignment))","handlingStrategy":"validation","validationCode":"raise ArgumentError unless params[:association_object].present? || params[:id].present?","typeGuard":"def has_association_target?(params) = params[:association_object].present? || params[:id].present?","tryCatchPattern":"begin\n  RubricAssociation.generate(user, rubric, context, params)\nrescue RuntimeError => e\n  raise unless e.message == \"association required\"\n  respond_with_missing_association\nend","preventionTips":["Always supply association_object for new rubric associations","Verify :id associations match context before relying on them","Don't strip :association_object from params in controllers/importers"],"tags":["ruby","rails","rubrics","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}