{"record":{"id":"2602086bb5795285","repo":"instructure/canvas-lms","slug":"anonymous-assignments-cannot-be-hidden-by-section","errorCode":null,"errorMessage":"Anonymous assignments cannot be hidden by section","messagePattern":"Anonymous assignments cannot be hidden by section","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/hide_assignment_grades_for_sections.rb","lineNumber":45,"sourceCode":"  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 hidden by section before grades are published\"\n    end\n    raise GraphQL::ExecutionError, \"Anonymous assignments cannot be hidden by section\" if assignment.anonymize_students?\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.graded : assignment.submissions\n    submissions_scope = submissions_scope.joins(user: :enrollments).merge(visible_enrollments)\n\n    progress = course.progresses.new(tag: \"hide_assignment_grades_for_sections\")\n\n    if progress.save\n      progress.process_job(\n        assignment,\n        :hide_submissions,\n        { preserve_method_args: true, priority: Delayed::HIGH_PRIORITY },\n        progress:,","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/hide_assignment_grades_for_sections.rb#L27-L63","documentation":"Anonymous-student assignments (assignment.anonymize_students?) cannot have grades hidden or posted per-section, since filtering by section would link posted/hidden grade visibility to identifiable section membership. The mutation refuses the request up front.","triggerScenarios":"Calling hideAssignmentGradesForSections on an assignment where 'Grade Anonymously' (anonymize_students) is on, with any section_ids.","commonSituations":"TA workflows in anonymous-grading assignments where per-section scoping is habitual; tooling that generically applies section filters to all assignments; confusion between anonymous_grading (provisional/moderated anonymity) and anonymize_students (grader anonymity) flags.","solutions":["Call the whole-assignment hide (hideAssignmentGrades without section_ids) instead, if allowed — note anonymized assignments restrict posting entirely; check policy.","Disable 'Grade Anonymously' on the assignment (if no submissions/grades yet) when section-level grade management is required.","In UI, hide/disable the section picker whenever assignment.anonymizeStudents is true.","Distinguish the flags in client logic: anonymizeStudents vs anonymousGrading trigger different restrictions."],"exampleFix":"// before\nawait HideBySection.mutate({ assignmentId, sectionIds });\n// after\nif (assignment.anonymizeStudents) {\n  showError('Anonymous assignments cannot be managed by section');\n} else {\n  await HideBySection.mutate({ assignmentId, sectionIds });\n}","handlingStrategy":"validation","validationCode":"if (assignment.anonymizeStudents && sectionIds?.length) {\n  throw new ValidationError('Section-scoped hide is unavailable for anonymized assignments');\n}","typeGuard":"const allowsSectionScoping = (a) => Boolean(a && !a.anonymizeStudents && !a.anonymousGrading);","tryCatchPattern":"try { await hideBySection({ assignmentId, sectionIds }); }\ncatch (e) {\n  if (String(e).includes('Anonymous assignments')) { showError('Use whole-assignment grade management for anonymized assignments'); return; }\n  throw e;\n}","preventionTips":["Disable section pickers when assignment.anonymizeStudents is true","Distinguish anonymizeStudents vs anonymousGrading flags in client models","Review grade-tooling defaults that always pass section_ids","Test workflows against anonymized assignment fixtures"],"tags":["graphql","anonymous-grading","canvas-lms"],"backgroundTag":"unsupported-operation","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"}