{"record":{"id":"25b9f45e55e8027d","repo":"instructure/canvas-lms","slug":"assignments-under-moderation-cannot-be-posted-by-section","errorCode":null,"errorMessage":"Assignments under moderation cannot be posted by section before grades are published","messagePattern":"Assignments under moderation cannot be posted by section before grades are published","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/post_assignment_grades_for_sections.rb","lineNumber":44,"sourceCode":"  argument :section_ids, [ID], required: true, prepare: GraphQLHelpers.relay_or_legacy_ids_prepare_func(\"Section\")\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 = course.course_sections.where(id: input[:section_ids])\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 by section before grades are published\"\n    end\n    raise GraphQL::ExecutionError, \"Anonymous assignments cannot be posted by section\" if assignment.anonymous_grading?\n\n    if sections.empty? || sections.count != input[:section_ids].size\n      raise GraphQL::ExecutionError, \"Invalid section ids\"\n    end\n\n    visible_enrollments = course.apply_enrollment_visibility(course.student_enrollments, current_user, sections)\n\n    submissions_scope = input[:graded_only] ? assignment.submissions.postable : assignment.submissions\n    submissions_scope = submissions_scope.joins(user: :enrollments).merge(visible_enrollments)\n    progress = course.progresses.new(tag: \"post_assignment_grades_for_sections\")\n\n    posting_params = {\n      graded_only: !!input[:graded_only],\n      section_names: sections&.pluck(:name)\n    }\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/post_assignment_grades_for_sections.rb#L26-L62","documentation":"PostAssignmentGradesForSections requires grades to be published before posting per-section; moderated assignments that have not had provisional grades released trigger this section-specific variant of the moderation error.","triggerScenarios":"postAssignmentGradesForSections on a moderated assignment while assignment.grades_published? is still false.","commonSituations":"Integration scripts posting section-by-section during an active moderation period.","solutions":["Have the moderator publish provisional grades first.","Poll assignment.grades_published? and schedule the section posts after publication.","If moderation is unintended, adjust the assignment's moderated grading setting."],"exampleFix":"// before\nawait postAssignmentGradesForSections({input: {assignmentId, sectionIds}});\n// after\nif (!assignment.gradesPublished) throw new Error(\"Await grade publication\");\nawait postAssignmentGradesForSections({input: {assignmentId, sectionIds}});","handlingStrategy":"validation","validationCode":"if (!assignment.gradesPublished) throw new Error('Publish grades before posting by section');","typeGuard":null,"tryCatchPattern":"try { await postSections(); } catch (e) { if (/posted by section before grades are published/.test(e.message)) deferUntilPublished(); }","preventionTips":["Gate section-posting UI on grades_published state.","Automate posts only after publication webhooks fire.","Document moderation workflow for integrators."],"tags":["graphql","moderated-grading","sections"],"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"}