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

Anonymous assignments cannot be posted by section

Error message

Anonymous assignments cannot be posted by section

What it means

PostAssignmentGradesForSections always forbids anonymous grading assignments: per-section posting would leak which students are in which section relative to grades, breaking anonymity, so any anonymous_grading? assignment raises this unconditionally.

Solutions

  1. Skip anonymous assignments in batch posting logic, or use the non-section postAssignmentGrades mutation for all students.
  2. Filter assignments by !anonymous_grading? before scheduling section posts.
  3. Surfacing a clear UI message that anonymous assignments cannot be posted by section.

Example fix

// before
sections.forEach(s => postAssignmentGradesForSections({assignmentId, sectionIds: [s.id]}));
// after
if (assignment.anonymousGrading) {
  await postAssignmentGrades({assignmentId}); // post all at once
} else {
  sections.forEach(s => postAssignmentGradesForSections({assignmentId, sectionIds: [s.id]}));
}
Defensive patterns

Strategy: validation

Validate before calling

if (assignment.anonymousGrading) throw new Error('Use postAssignmentGrades (whole course) for anonymous assignments');

Type guard

const canPostBySection = (a) => !a.anonymousGrading;

Try / catch

try { await postSections(); } catch (e) { if (/Anonymous assignments cannot be posted by section/.test(e.message)) fallbackToWholeCoursePost(); }

Prevention

When it happens

Trigger: Any call to postAssignmentGradesForSections where the target assignment has anonymous_grading? true — regardless of which sections are passed.

Common situations: Automated per-section posting jobs encountering an anonymously graded assignment in the batch.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

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

  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)
    }

    if progress.save
      progress.process_job(

View on GitHub (pinned to 1c9f0bb801)