instructure/canvas-lms · error · GraphQL::ExecutionError
Assignments under moderation cannot be posted before grades…
Error message
Assignments under moderation cannot be posted before grades are published
What it means
PostAssignmentGrades refuses to post when assignment.grades_published? is false, i.e. the assignment is a moderated grading assignment whose grades have not yet been published by the moderator. Posting is only allowed after publication.
Solutions
- Wait for grades to be published: have the moderator publish provisional grades in SpeedGrader/moderation page.
- Check assignment.grades_published? before calling the mutation and defer the post.
- If moderation is not intended, remove the final grader / moderated grading setting on the assignment.
Example fix
// before
await postAssignmentGrades({assignmentId, ...});
// after
if (!assignment.gradesPublished) {
throw new Error("Publish provisional grades before posting");
}
await postAssignmentGrades({assignmentId, ...}); Defensive patterns
Strategy: validation
Validate before calling
if (!assignment.gradesPublished) { queueForLater(assignmentId); return; } Try / catch
try { await post(); } catch (e) { if (/grades are published/.test(e.message)) scheduleRetryAfterPublication(); } Prevention
- Check the moderation state (grades_published) before enabling post controls.
- Subscribe to grade-publication events/webhooks to trigger posts.
- Educate users that moderated assignments post only after release.
When it happens
Trigger: Calling postAssignmentGrades on a moderated assignment before the moderator clicks 'Release Grades'/publishes provisional grades.
Common situations: Automations or SIS integrations posting grades during a moderation window; teachers attempting to post before the moderation workflow completes.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Assignment group category id and discussion topic group…
- assignment not found
- Assignments under moderation cannot be hidden before grades…
- Assignments under moderation cannot be hidden by section…
- Assignments under moderation cannot be posted by section…
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/ca5aaaf354609f36.
Report an issue: GitHub.
Appendix: source
Thrown at app/graphql/mutations/post_assignment_grades.rb:46
argument :skip_student_ids, [ID], required: false, prepare: GraphQLHelpers.relay_or_legacy_ids_prepare_func("User")
field :assignment, Types::AssignmentType, null: true
field :progress, Types::ProgressType, null: true
field :sections, [Types::SectionType], null: true
def resolve(input:)
begin
assignment = AbstractAssignment.find_assignment_or_peer_review(input[:assignment_id])
course = assignment.context
sections = input[:section_ids] ? course.course_sections.where(id: input[:section_ids]) : nil
rescue ActiveRecord::RecordNotFound
raise GraphQL::ExecutionError, "not found"
end
verify_authorized_action!(assignment, :grade)
unless assignment.grades_published?
raise GraphQL::ExecutionError, "Assignments under moderation cannot be posted before grades are published"
end
raise GraphQL::ExecutionError, "Anonymous assignments cannot be posted by section" if sections && assignment.anonymous_grading?
if input[:graded_only] && assignment.anonymous_grading
raise GraphQL::ExecutionError, "Anonymous assignments cannot be posted by graded only"
end
if input[:only_student_ids] && input[:skip_student_ids]
raise GraphQL::ExecutionError, I18n.t("{a} and {b} cannot be used together", a: "only_student_ids", b: "skip_student_ids")
end
visible_enrollments = course.apply_enrollment_visibility(course.student_enrollments, current_user, sections)
visible_enrollments = visible_enrollments.where(user_id: input[:only_student_ids]) if input[:only_student_ids]
visible_enrollments = visible_enrollments.where.not(user_id: input[:skip_student_ids]) if input[:skip_student_ids]
submissions_scope = input[:graded_only] ? assignment.submissions.postable : assignment.submissions
submissions_scope = submissions_scope.joins(user: :enrollments).merge(visible_enrollments)
submission_ids = submissions_scope.pluck(:id)View on GitHub (pinned to 1c9f0bb801)