instructure/canvas-lms · error · PeerReview::InvalidGradingTypeError
Peer review sub assignments cannot have a not_graded…
Error message
Peer review sub assignments cannot have a not_graded grading type
What it means
PeerReview::Validations#validate_grading_type raises PeerReview::InvalidGradingTypeError when a grading type of "not_graded" is supplied for a peer review sub assignment. Sub assignments must carry a grade; the library explicitly rejects the not_graded enum value.
Solutions
- Use a graded grading type such as "points", "percent", or "pass_fail" for the sub assignment.
- Only propagate grading_type from the parent when the parent is actually graded; otherwise default to "points".
- Validate grading_type in your client before submitting the request.
Example fix
// before sub = PeerReview::SubAssignmentCreator.new(assignment: parent, grading_type: "not_graded") // after sub = PeerReview::SubAssignmentCreator.new( assignment: parent, grading_type: parent.grading_type == "not_graded" ? "points" : parent.grading_type )
Defensive patterns
Strategy: validation
Validate before calling
rejected = %w[not_graded] raise ArgumentError, "invalid grading type" if rejected.include?(params[:grading_type])
Try / catch
begin
service.call
rescue PeerReview::InvalidGradingTypeError => e
render json: { error: e.message }, status: :unprocessable_entity
end Prevention
- Whitelist allowed grading types (points, percent, pass_fail) in params
- Never copy parent grading_type blindly
- Add schema-level validation on API payloads
When it happens
Trigger: Creating/updating a peer review sub assignment with grading_type: "not_graded" in the API payload or service params.
Common situations: Copying parent assignment attributes (including not_graded) onto the sub assignment; API clients defaulting grading_type to not_graded; UI workflows that let users pick not_graded for review sub assignments.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Due date cannot be before available from date
- Invalid parent assignment
- Must be a group assignment to create group overrides
- Peer review sub assignment does not exist
- Peer review sub assignment exists
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/b9570dea0497ebe2.
Report an issue: GitHub.
Appendix: source
Thrown at app/services/peer_review/validations.rb:40
unless assignment.present? && assignment.is_a?(Assignment) && assignment.persisted?
raise PeerReview::InvalidParentAssignmentError, I18n.t("Invalid parent assignment")
end
end
def validate_peer_reviews_enabled(assignment)
unless assignment.peer_reviews?
raise PeerReview::PeerReviewsNotEnabledError, I18n.t("Peer reviews are not enabled for this assignment")
end
end
def validate_feature_enabled(assignment)
unless assignment.context.feature_enabled?(:peer_review_allocation_and_grading)
raise PeerReview::FeatureDisabledError, I18n.t("Peer Review Allocation and Grading feature flag is disabled")
end
end
def validate_grading_type(grading_type)
raise PeerReview::InvalidGradingTypeError, I18n.t("Peer review sub assignments cannot have a not_graded grading type") if grading_type == "not_graded"
end
def validate_assignment_submission_types(assignment)
if assignment.external_tool?
raise PeerReview::InvalidAssignmentSubmissionTypesError, I18n.t("Peer reviews cannot be used with External Tool assignments")
end
if assignment.submission_types == "discussion_topic"
raise PeerReview::InvalidAssignmentSubmissionTypesError, I18n.t("Peer reviews cannot be used with Discussion Topic assignments")
end
end
def validate_peer_review_sub_assignment_exists(assignment)
if assignment.peer_review_sub_assignment.blank?
raise PeerReview::SubAssignmentNotExistError, I18n.t("Peer review sub assignment does not exist")
end
end
View on GitHub (pinned to 1c9f0bb801)