{"record":{"id":"51b23030b5be305c","repo":"instructure/canvas-lms","slug":"e-model-not-found-set-override-status","errorCode":null,"errorMessage":"#{e.model} not found","messagePattern":"#(.+?) not found","errorType":"exception","errorClass":"GraphQL::ExecutionError","httpStatus":null,"severity":"error","filePath":"app/graphql/mutations/set_override_status.rb","lineNumber":43,"sourceCode":"    field :grades, Types::GradesType, null: true\n\n    def resolve(input:)\n      raise GraphQL::ExecutionError, \"custom gradebook statuses feature flag is disabled\" unless Account.site_admin.feature_enabled?(:custom_gradebook_statuses)\n\n      score = score(input:)\n      unless score.grants_right?(current_user, session, :update_custom_status)\n        raise GraphQL::ExecutionError, I18n.t(\"Insufficient permissions\")\n      end\n\n      enrollment = Enrollment.find_by(id: input[:enrollment_id])\n      custom_grade_status = get_custom_grade_status(input:)\n      grading_period_id = input[:grading_period_id]\n\n      updated_score = enrollment.update_override_status(custom_grade_status:, grading_period_id:)\n      InstStatsd::Statsd.distributed_increment(\"custom_grade_status.applied_to.final_grade\")\n      { grades: updated_score }\n    rescue ActiveRecord::RecordNotFound => e\n      raise GraphQL::ExecutionError, \"#{e.model} not found\"\n    rescue ActiveRecord::RecordInvalid => e\n      errors_for(e.record)\n    end\n\n    private\n\n    def score(input:)\n      Score.find_by!(\n        assignment_group_id: nil,\n        course_score: input[:grading_period_id].blank?,\n        enrollment_id: input[:enrollment_id],\n        grading_period_id: input[:grading_period_id],\n        root_account_id: context[:domain_root_account].id\n      )\n    end\n\n    def get_custom_grade_status(input:)\n      id = input[:custom_grade_status_id]","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/graphql/mutations/set_override_status.rb#L25-L61","documentation":"Within SetOverrideStatus, any ActiveRecord::RecordNotFound raised while loading the enrollment, score, or custom grade status is re-raised as \"#{e.model} not found\", naming the missing model class. It also rescues RecordInvalid into validation errors separately.","triggerScenarios":"Passing a nonexistent enrollment_id, a custom_grade_status_id that does not exist (CustomGradeStatus.find fails), or a score lookup miss for the enrollment/grading period pair.","commonSituations":"Custom grade status deleted by an admin after the UI loaded; enrollment id from a different course; typing a global vs local ID mismatch in GraphQL relay-style ID fields.","solutions":["Pre-verify each ID: Enrollment.find_by(id: ...), CustomGradeStatus.find_by(id: ...) before calling","Refresh the custom grade status list from the course before applying","Check whether the GraphQL global ID needs conversion to a local numeric id"],"exampleFix":"// before\ncustomGradeStatus(enrollmentId: 12, customGradeStatusId: 77)\n// after\nstatus = CustomGradeStatus.find_by(id: 77)\nif status\n  customGradeStatus(enrollmentId: 12, customGradeStatusId: 77)\nelse\n  Rails.logger.warn(\"custom grade status 77 missing\")\nend","handlingStrategy":"validation","validationCode":"// Ruby\nok = Enrollment.find_by(id: enrollment_id) && CustomGradeStatus.find_by(id: status_id)","typeGuard":"// Ruby\nstatus = CustomGradeStatus.find_by(id: custom_grade_status_id)\nproceed = status.is_a?(CustomGradeStatus)","tryCatchPattern":"// Ruby\nbegin\n  mutation\nrescue GraphQL::ExecutionError => e\n  # e.message like \"Enrollment not found\" / \"CustomGradeStatus not found\"\n  refresh_missing_record(e.message)\nend","preventionTips":["Refresh custom grade status lists before applying (statuses can be deleted)","Convert relay global ids to local ids consistently","Check both enrollment and status exist in the same context"],"tags":["graphql","ruby","record-not-found","gradebook"],"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"}