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

PostAssignmentGrades raises this when section_ids are supplied for an assignment with anonymous_grading enabled. Anonymous assignments must be posted for all students at once so anonymity is not broken by per-section posting.

Solutions

  1. Remove section_ids from the input and post the anonymous assignment for the whole course.
  2. Disable anonymous grading on the assignment if section-level posting is genuinely required (usually not possible after submissions).
  3. Guard client code: if assignment.anonymousGrading, hide/disable the section picker.

Example fix

// before
postAssignmentGrades(input: {assignmentId, sectionIds: ["17"], ...})
// after
const input = { assignmentId, gradedOnly: true };
if (!assignment.anonymousGrading) input.sectionIds = sectionIds;
await postAssignmentGrades({input});
Defensive patterns

Strategy: validation

Validate before calling

if (assignment.anonymousGrading && sectionIds?.length) throw new Error('Anonymous assignments cannot be posted by section');

Try / catch

try { await post(); } catch (e) { if (/cannot be posted by section/.test(e.message)) resetSectionFilter(); }

Prevention

When it happens

Trigger: postAssignmentGrades with both a non-empty section_ids input and an assignment whose anonymous_grading? is true.

Common situations: UIs that preserve a previously selected section filter when the teacher later enables anonymous grading; scripts posting by section copied from non-anonymous flows.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at app/graphql/mutations/post_assignment_grades.rb:48

  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)
    progress = course.progresses.new(tag: "post_assignment_grades")

View on GitHub (pinned to 1c9f0bb801)