{"record":{"id":"2cc07aa375163d0d","repo":"instructure/canvas-lms","slug":"an-assignment-with-that-id-does-not-exist","errorCode":null,"errorMessage":"An assignment with that id does not exist","messagePattern":"An assignment with that id does not exist","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/set_assignment_post_policy.rb","lineNumber":36,"sourceCode":"# with this program. If not, see <http://www.gnu.org/licenses/>.\n#\n\nclass Mutations::SetAssignmentPostPolicy < Mutations::BaseMutation\n  graphql_name \"SetAssignmentPostPolicy\"\n\n  argument :assignment_id, ID, required: true, prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func(\"Assignment\")\n  argument :post_comments_at, String, required: false\n  argument :post_grades_at, String, required: false\n  argument :post_manually, Boolean, required: true\n\n  field :post_policy, Types::PostPolicyType, 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    rescue ActiveRecord::RecordNotFound\n      raise GraphQL::ExecutionError, \"An assignment with that id does not exist\"\n    end\n\n    verify_authorized_action!(course, :manage_grades)\n\n    if input[:post_manually] == false\n      raise GraphQL::ExecutionError, I18n.t(\"Anonymous assignments must be manually posted\") if assignment.anonymous_grading?\n\n      if assignment.moderated_grading? && !assignment.grades_published?\n        raise GraphQL::ExecutionError, I18n.t(\"Moderated assignments must be manually posted until grades are released\")\n      end\n    end\n\n    assignment.ensure_post_policy(post_manually: input[:post_manually])\n\n    if Account.site_admin.feature_enabled?(:scheduled_feedback_releases) && input[:post_manually] == true\n      is_post_params_blank = input[:post_comments_at].blank? && input[:post_grades_at].blank?\n\n      if !is_post_params_blank","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/set_assignment_post_policy.rb#L18-L54","documentation":"SetAssignmentPostPolicy looks up the assignment with `AbstractAssignment.find_assignment_or_peer_review(input[:assignment_id])` and rescues ActiveRecord::RecordNotFound, raising GraphQL::ExecutionError \"An assignment with that id does not exist\". This is an explicit, user-friendly conversion of a missing-assignment lookup into a GraphQL error before any authorization or post-policy changes occur.","triggerScenarios":"Calling setAssignmentPostPolicy with an assignment_id that does not exist, was deleted, or (for peer review lookups) whose root/sub-assignment cannot be resolved on the current shard.","commonSituations":"Automated scripts iterating a cached assignment list after some assignments were deleted; copying an id from a peer-review sub-assignment URL; wrong course context or shard; ids taken from another Canvas instance (test vs production).","solutions":["Verify the assignment id by querying it first (e.g. legacyNode with type Assignment) before mutating.","Refresh any cached assignment lists to drop deleted assignments.","Confirm you are calling against the correct Canvas environment/shard.","If the id came from a peer review, use the id expected by find_assignment_or_peer_review (the assignment id, not the peer review sub-id)."],"exampleFix":"// before\nsetAssignmentPostPolicy(input: { assignmentId: \"404\", postManually: true })\n// after\nquery { legacyNode(__typename: \"Assignment\", id: \"404\") { _id } }\n// only then call the mutation with a confirmed id","handlingStrategy":"validation","validationCode":"const node = await client.query({ query: LEGACY_NODE_QUERY, variables: { id: assignmentId, type: 'Assignment' } });\nif (!node?.data?.legacyNode) throw new Error(`assignment ${assignmentId} does not exist`);","typeGuard":"function assignmentExists(node) { return node?.__typename === 'Assignment' && node._id != null; }","tryCatchPattern":"try {\n  await client.mutate({ mutation: SET_ASSIGNMENT_POST_POLICY, variables });\n} catch (e) {\n  if (e.graphQLErrors?.some(g => g.message.includes('does not exist'))) {\n    // drop the id from local state and prompt the user to reselect\n  } else { throw e; }\n}","preventionTips":["Refresh cached assignment lists before bulk policy updates","Use the assignment id, not peer-review sub-ids","Verify ids against the target environment (test vs production Canvas)","Guard bulk scripts with per-id existence checks"],"tags":["graphql","post-policy","assignment","record-not-found"],"backgroundTag":"record-not-found","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"}