{"record":{"id":"830f9a5630a3fca4","repo":"instructure/canvas-lms","slug":"not-found-create-submission-comment","errorCode":null,"errorMessage":"not found","messagePattern":"not found","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/create_submission_comment.rb","lineNumber":54,"sourceCode":"  argument :submission_id, ID, required: true, prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func(\"Submission\")\n\n  field :submission_comment, Types::SubmissionCommentType, null: true\n\n  def resolve(input:)\n    submission = Submission.find input[:submission_id]\n    verify_authorized_action!(submission, :comment)\n\n    latest_attempt = submission.context.feature_enabled?(:assignments_2_student) ? submission.attempt : nil\n    opts = {\n      attempt: input[:attempt] || latest_attempt,\n      author: current_user,\n      comment: input[:comment],\n      draft_comment: input[:draft_comment]\n    }\n\n    if input[:media_object_id].present?\n      media_objects = MediaObject.by_media_id(input[:media_object_id])\n      raise GraphQL::ExecutionError, \"not found\" if media_objects.empty?\n\n      opts[:media_comment_id] = input[:media_object_id]\n\n      if input[:media_object_type].present?\n        opts[:media_comment_type] = input[:media_object_type]\n      end\n    end\n\n    file_ids = (input[:file_ids] || []).uniq\n    unless file_ids.empty?\n      attachments = Attachment.where(id: file_ids).to_a\n      raise GraphQL::ExecutionError, \"not found\" unless attachments.length == file_ids.length\n\n      attachments.each do |a|\n        verify_authorized_action!(a, :attach_to_submission_comment)\n        a.ok_for_submission_comment = true\n      end\n      opts[:attachments] = attachments","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/create_submission_comment.rb#L36-L72","documentation":"CreateSubmissionComment#resolve raises 'not found' when MediaObject.by_media_id(input[:media_object_id]) returns empty, i.e. no MediaObject row matches the given media_id for the current context. The media_id namespace is scoped (by_media_id filters by context/user), so a valid-looking ID from elsewhere still yields an empty relation.","triggerScenarios":"Passing media_object_id that was never uploaded, was deleted, belongs to another user/course context, or is an attachment ID rather than a media_id (media_id is the 'm-<hash>' style identifier, not a numeric DB id).","commonSituations":"Recording/Studio upload flow failed silently so the media object never persisted; copying media IDs between courses; confusing canvas media_id with file/attachment ids.","solutions":["Confirm the media upload completed and the media object exists (query MediaObject/media comment by that id for the same user/context).","Pass the media_id (kaltura-style m-... string), not a numeric attachment/file id.","Re-upload the media if the object was deleted or never created, then retry the comment mutation.","Omit media_object_id if no media comment is intended instead of sending an empty/invalid value."],"exampleFix":"// before\nconst input = { submissionId, comment, mediaObjectId: attachmentId } // wrong id kind\n// after\nconst media = await uploadAndGetMediaObject(file) // returns m-... media_id\nif (!media) throw new Error('Upload failed; cannot attach media comment')\nconst input = { submissionId, comment, mediaObjectId: media.mediaId }","handlingStrategy":"validation","validationCode":"if (mediaObjectId && !/^m-[A-Za-z0-9]+$/.test(mediaObjectId)) throw new Error('media_object_id must be a media id, not a file id')\n// and confirm the upload completed before commenting\nif (uploadPending) throw new Error('wait for media upload to finish')","typeGuard":"function isMediaObjectId(v) { return typeof v === 'string' && v.startsWith('m-') && v.length > 2 }","tryCatchPattern":"try {\n  await gql(CREATE_SUBMISSION_COMMENT, { input })\n} catch (e) {\n  if (e.message === 'not found' && input.mediaObjectId) { dropMediaAndResendWithoutMedia() }\n  else throw e\n}","preventionTips":["Gate comment submission on successful media upload confirmation.","Distinguish media ids (m-...) from attachment/file numeric ids.","Keep media objects within the same user/context as the comment."],"tags":["graphql","not-found","media","canvas-lms"],"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"}