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

Assignments under moderation cannot be hidden before grades…

Error message

Assignments under moderation cannot be hidden before grades are published

What it means

The mutation blocks hiding assignment grades while the assignment is still in moderated grading and its grades are not yet published (grades_published? is false). This protects provisional grades from being posted/hidden before the moderator finalizes them.

Solutions

  1. Wait for a moderator to publish grades (Assignment > Grade > 'Post Grades' / grades_published!); check assignment.grades_published_at first.
  2. Complete moderated grading via the moderation page or ModerationSet/Assignment#moderated_grading workflow before hiding.
  3. If the assignment shouldn't be moderated, disable moderated_grading (before grading) or use a non-moderated assignment.
  4. Gate client UI: hide the 'Hide Grades' action unless gradesPublished is true in the assignment GraphQL data.

Example fix

// before
await HideAssignmentGrades.mutate({ assignmentId });
// after
const a = await fetchAssignment(assignmentId);
if (a.moderatedGrading && !a.gradesPublished) throw new Error('Grades not yet published for moderated assignment');
await HideAssignmentGrades.mutate({ assignmentId });
Defensive patterns

Strategy: validation

Validate before calling

const a = await fetchAssignment(assignmentId);
if (a.moderatedGrading && !a.gradesPublished) throw new SkipError('Awaiting moderator grade publication');
await hideGrades({ assignmentId });

Type guard

const canHideGrades = (a) => Boolean(a && (!a.moderatedGrading || a.gradesPublished === true));

Try / catch

try { await hideGrades({ assignmentId }); }
catch (e) {
  if (String(e).includes('grades are published')) { await notifyModerator(assignmentId); return; }
  throw e;
}

Prevention

When it happens

Trigger: Calling hideAssignmentGrades on an assignment with moderated_grading enabled before a moderator has published final grades; calling it right after graders finish but before the publish action runs.

Common situations: Teacher with grade permissions (but not moderator role) attempting hide/post on a moderated assignment; automation that posts/hides grades immediately after submission upload on moderated assignments; UI state that doesn't reflect unpublished moderated grades.

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/31c65b85e7eb18b8. Report an issue: GitHub.

Appendix: source

Thrown at app/graphql/mutations/hide_assignment_grades.rb:45

  argument :skip_student_ids, [ID], required: false, prepare: GraphQLHelpers.relay_or_legacy_ids_prepare_func("User")

  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 hidden before grades are published"
    end
    raise GraphQL::ExecutionError, "Anonymous assignments cannot be posted by section" if sections && assignment.anonymous_grading?

    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 = assignment.submissions.active.joins(user: :enrollments)
    submissions_scope = course.apply_enrollment_visibility(submissions_scope, current_user).merge(visible_enrollments)
    progress = course.progresses.new(tag: "hide_assignment_grades")

    if progress.save
      progress.process_job(
        assignment,

View on GitHub (pinned to 1c9f0bb801)