{"record":{"id":"ca5aaaf354609f36","repo":"instructure/canvas-lms","slug":"assignments-under-moderation-cannot-be-posted-before-grades","errorCode":null,"errorMessage":"Assignments under moderation cannot be posted before grades are published","messagePattern":"Assignments under moderation cannot be posted before grades are published","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/post_assignment_grades.rb","lineNumber":46,"sourceCode":"  argument :skip_student_ids, [ID], required: false, prepare: GraphQLHelpers.relay_or_legacy_ids_prepare_func(\"User\")\n\n  field :assignment, Types::AssignmentType, null: true\n  field :progress, Types::ProgressType, null: true\n  field :sections, [Types::SectionType], null: true\n\n  def resolve(input:)\n    begin\n      assignment = AbstractAssignment.find_assignment_or_peer_review(input[:assignment_id])\n      course = assignment.context\n      sections = input[:section_ids] ? course.course_sections.where(id: input[:section_ids]) : nil\n    rescue ActiveRecord::RecordNotFound\n      raise GraphQL::ExecutionError, \"not found\"\n    end\n\n    verify_authorized_action!(assignment, :grade)\n\n    unless assignment.grades_published?\n      raise GraphQL::ExecutionError, \"Assignments under moderation cannot be posted before grades are published\"\n    end\n    raise GraphQL::ExecutionError, \"Anonymous assignments cannot be posted by section\" if sections && assignment.anonymous_grading?\n\n    if input[:graded_only] && assignment.anonymous_grading\n      raise GraphQL::ExecutionError, \"Anonymous assignments cannot be posted by graded only\"\n    end\n\n    if input[:only_student_ids] && input[:skip_student_ids]\n      raise GraphQL::ExecutionError, I18n.t(\"{a} and {b} cannot be used together\", a: \"only_student_ids\", b: \"skip_student_ids\")\n    end\n\n    visible_enrollments = course.apply_enrollment_visibility(course.student_enrollments, current_user, sections)\n    visible_enrollments = visible_enrollments.where(user_id: input[:only_student_ids]) if input[:only_student_ids]\n    visible_enrollments = visible_enrollments.where.not(user_id: input[:skip_student_ids]) if input[:skip_student_ids]\n\n    submissions_scope = input[:graded_only] ? assignment.submissions.postable : assignment.submissions\n    submissions_scope = submissions_scope.joins(user: :enrollments).merge(visible_enrollments)\n    submission_ids = submissions_scope.pluck(:id)","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/post_assignment_grades.rb#L28-L64","documentation":"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.","triggerScenarios":"Calling postAssignmentGrades on a moderated assignment before the moderator clicks 'Release Grades'/publishes provisional grades.","commonSituations":"Automations or SIS integrations posting grades during a moderation window; teachers attempting to post before the moderation workflow completes.","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."],"exampleFix":"// before\nawait postAssignmentGrades({assignmentId, ...});\n// after\nif (!assignment.gradesPublished) {\n  throw new Error(\"Publish provisional grades before posting\");\n}\nawait postAssignmentGrades({assignmentId, ...});","handlingStrategy":"validation","validationCode":"if (!assignment.gradesPublished) { queueForLater(assignmentId); return; }","typeGuard":null,"tryCatchPattern":"try { await post(); } catch (e) { if (/grades are published/.test(e.message)) scheduleRetryAfterPublication(); }","preventionTips":["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."],"tags":["graphql","moderated-grading","assignments","workflow"],"backgroundTag":"invalid-state-transition","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"}