instructure/canvas-lms · error · GraphQL::ExecutionError

Assignments under moderation cannot be posted by section…

Error message

Assignments under moderation cannot be posted by section before grades are published

What it means

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.

Solutions

  1. Have the moderator publish provisional grades first.
  2. Poll assignment.grades_published? and schedule the section posts after publication.
  3. If moderation is unintended, adjust the assignment's moderated grading setting.

Example fix

// before
await postAssignmentGradesForSections({input: {assignmentId, sectionIds}});
// after
if (!assignment.gradesPublished) throw new Error("Await grade publication");
await postAssignmentGradesForSections({input: {assignmentId, sectionIds}});
Defensive patterns

Strategy: validation

Validate before calling

if (!assignment.gradesPublished) throw new Error('Publish grades before posting by section');

Try / catch

try { await postSections(); } catch (e) { if (/posted by section before grades are published/.test(e.message)) deferUntilPublished(); }

Prevention

When it happens

Trigger: postAssignmentGradesForSections on a moderated assignment while assignment.grades_published? is still false.

Common situations: Integration scripts posting section-by-section during an active moderation period.

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


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/25b9f45e55e8027d. Report an issue: GitHub.

Appendix: source

Thrown at app/graphql/mutations/post_assignment_grades_for_sections.rb:44

  argument :section_ids, [ID], required: true, prepare: GraphQLHelpers.relay_or_legacy_ids_prepare_func("Section")

  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 = course.course_sections.where(id: input[:section_ids])
    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 by section before grades are published"
    end
    raise GraphQL::ExecutionError, "Anonymous assignments cannot be posted by section" if assignment.anonymous_grading?

    if sections.empty? || sections.count != input[:section_ids].size
      raise GraphQL::ExecutionError, "Invalid section ids"
    end

    visible_enrollments = course.apply_enrollment_visibility(course.student_enrollments, current_user, sections)

    submissions_scope = input[:graded_only] ? assignment.submissions.postable : assignment.submissions
    submissions_scope = submissions_scope.joins(user: :enrollments).merge(visible_enrollments)
    progress = course.progresses.new(tag: "post_assignment_grades_for_sections")

    posting_params = {
      graded_only: !!input[:graded_only],
      section_names: sections&.pluck(:name)
    }

View on GitHub (pinned to 1c9f0bb801)