{"record":{"id":"852b4900e52818ec","repo":"instructure/canvas-lms","slug":"student-ids-are-not-in-course","errorCode":null,"errorMessage":"Student ids are not in course","messagePattern":"Student ids are not in course","errorType":"validation","errorClass":"PeerReview::StudentIdsNotInCourseError","httpStatus":null,"severity":"error","filePath":"app/services/peer_review/validations.rb","lineNumber":221,"sourceCode":"    raise PeerReview::OverrideNotFoundError, I18n.t(\"Override does not exist\") unless override.present?\n  end\n\n  def validate_section_exists(section)\n    raise PeerReview::SectionNotFoundError, I18n.t(\"Section does not exist\") unless section.present?\n  end\n\n  def validate_course_exists(course)\n    raise PeerReview::CourseNotFoundError, I18n.t(\"Course does not exist\") unless course.present?\n  end\n\n  def validate_student_ids_required(student_ids)\n    if student_ids.nil? || student_ids == \"\" || student_ids.to_s.strip.empty? || (student_ids.is_a?(Array) && student_ids.empty?)\n      raise PeerReview::StudentIdsRequiredError, I18n.t(\"Student ids are required\")\n    end\n  end\n\n  def validate_student_ids_in_course(student_ids)\n    raise PeerReview::StudentIdsNotInCourseError, I18n.t(\"Student ids are not in course\") if student_ids.blank?\n  end\n\n  def validate_set_type_supported(set_type, services)\n    unless services.key?(set_type)\n      supported_types = services.keys.join(\", \")\n      raise PeerReview::SetTypeNotSupportedError,\n            I18n.t(\"Set type '%{set_type}' is not supported. Supported types are: %{supported_types}\", set_type:, supported_types:)\n    end\n  end\n\n  def validate_group_assignment_required(assignment)\n    unless assignment.group_category_id\n      raise PeerReview::GroupAssignmentRequiredError, I18n.t(\"Must be a group assignment to create group overrides\")\n    end\n  end\n\n  def validate_group_exists(group)\n    raise PeerReview::GroupNotFoundError, I18n.t(\"Group does not exist\") unless group.present?","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/peer_review/validations.rb#L203-L239","documentation":"PeerReview::StudentIdsNotInCourseError raised by validate_student_ids_in_course when the (non-blank-checked upstream) student_ids arrive blank — the ids supplied do not correspond to enrollments the validator can confirm in the course.","triggerScenarios":"Calling a peer review service where the resolved student id list is blank: ids from users not enrolled in the course, ids filtered out by visibility/permissions, or an empty resolution result passed onward.","commonSituations":"Students enrolled after the call's enrollment snapshot; ids from a different course's roster; observer/test-student ids used by mistake.","solutions":["Verify each id is an enrolled student in the target course before calling","Re-fetch the course's student roster and use those ids","Check for course/shard mismatch causing enrollment lookups to return nothing"],"exampleFix":"// before\nids = [451, 452] # ids from another course\nservice.call(student_ids: ids)\n// after\nids = course.students.where(id: [451, 452]).pluck(:id)\nraise ArgumentError, 'no valid students' if ids.empty?\nservice.call(student_ids: ids)","handlingStrategy":"validation","validationCode":"valid_ids = course.students.where(id: student_ids).pluck(:id)\nraise ArgumentError, 'no students from the list are enrolled in this course' if valid_ids.empty?","typeGuard":null,"tryCatchPattern":"begin\n  service.call(student_ids:)\nrescue PeerReview::StudentIdsNotInCourseError\n  render json: { error: 'Students must be enrolled in the course' }, status: :unprocessable_entity\nend","preventionTips":["Derive student ids from course.students rather than trusting client input","Re-resolve enrollments at call time; rosters change with SIS syncs","Filter out non-student roles (observers, designers) before calling"],"tags":["ruby","peer-review","enrollment","validation","canvas"],"backgroundTag":"invalid-argument-value","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"}