{"record":{"id":"e985d9ea94b4c031","repo":"instructure/canvas-lms","slug":"peer-reviews-are-not-enabled-for-this-assignment","errorCode":null,"errorMessage":"Peer reviews are not enabled for this assignment","messagePattern":"Peer reviews are not enabled for this assignment","errorType":"validation","errorClass":"PeerReview::PeerReviewsNotEnabledError","httpStatus":null,"severity":"error","filePath":"app/services/peer_review/validations.rb","lineNumber":29,"sourceCode":"#\n# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY\n# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more\n# details.\n#\n# You should have received a copy of the GNU Affero General Public License along\n# with this program. If not, see <http://www.gnu.org/licenses/>.\n\nmodule PeerReview::Validations\n  def validate_parent_assignment(assignment)\n    unless assignment.present? && assignment.is_a?(Assignment) && assignment.persisted?\n      raise PeerReview::InvalidParentAssignmentError, I18n.t(\"Invalid parent assignment\")\n    end\n  end\n\n  def validate_peer_reviews_enabled(assignment)\n    unless assignment.peer_reviews?\n      raise PeerReview::PeerReviewsNotEnabledError, I18n.t(\"Peer reviews are not enabled for this assignment\")\n    end\n  end\n\n  def validate_feature_enabled(assignment)\n    unless assignment.context.feature_enabled?(:peer_review_allocation_and_grading)\n      raise PeerReview::FeatureDisabledError, I18n.t(\"Peer Review Allocation and Grading feature flag is disabled\")\n    end\n  end\n\n  def validate_grading_type(grading_type)\n    raise PeerReview::InvalidGradingTypeError, I18n.t(\"Peer review sub assignments cannot have a not_graded grading type\") if grading_type == \"not_graded\"\n  end\n\n  def validate_assignment_submission_types(assignment)\n    if assignment.external_tool?\n      raise PeerReview::InvalidAssignmentSubmissionTypesError, I18n.t(\"Peer reviews cannot be used with External Tool assignments\")\n    end\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/peer_review/validations.rb#L11-L47","documentation":"PeerReview::Validations#validate_peer_reviews_enabled raises PeerReview::PeerReviewsNotEnabledError when the target assignment does not have `peer_reviews?` truthy. Peer review sub-assignments only make sense for assignments that have peer reviews turned on, so the library short-circuits when the parent assignment lacks the setting.","triggerScenarios":"Creating or manipulating a peer review sub assignment for an assignment whose `peer_reviews` attribute is false/unset; API calls to peer review endpoints without `peer_reviews: true` on the assignment.","commonSituations":"Assignment created through the API without the peer_reviews flag; admin disabled peer reviews after sub assignment creation; seeding scripts that forget `peer_reviews: true`.","solutions":["Set `peer_reviews: true` on the assignment (assignment.update!(peer_reviews: true)) before running peer review services.","Enable 'Peer Reviews' in the assignment edit UI before creating sub assignments.","Guard the service call with `assignment.peer_reviews?` and skip or return early when disabled."],"exampleFix":"// before\nPeerReview::SubAssignmentCreator.new(assignment: assignment).call # peer_reviews not set\n// after\nassignment.update!(peer_reviews: true)\nPeerReview::SubAssignmentCreator.new(assignment: assignment).call","handlingStrategy":"validation","validationCode":"return render json: { error: \"peer reviews disabled\" }, status: :unprocessable_entity unless assignment.peer_reviews?","typeGuard":null,"tryCatchPattern":"begin\n  service.call\nrescue PeerReview::PeerReviewsNotEnabledError => e\n  render json: { error: e.message }, status: :unprocessable_entity\nend","preventionTips":["Require peer_reviews: true in the request contract","Hide peer review UI until the assignment flag is on","Check the flag before enqueuing background jobs"],"tags":["peer-review","rails","configuration","validation"],"backgroundTag":"feature-not-enabled","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"}