{"record":{"id":"687c85846687ba53","repo":"instructure/canvas-lms","slug":"argument-is-not-an-account","errorCode":null,"errorMessage":"argument is not an Account","messagePattern":"argument is not an Account","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"app/models/grading_period_group.rb","lineNumber":60,"sourceCode":"\n    given do |user|\n      root_account&.associated_user?(user)\n    end\n    can :read\n\n    given do |user|\n      (course || root_account).grants_right?(user, :manage)\n    end\n    can :update and can :delete\n\n    given do |user|\n      root_account&.grants_right?(user, :manage)\n    end\n    can :create\n  end\n\n  def self.for(account)\n    raise ArgumentError, \"argument is not an Account\" unless account.is_a?(Account)\n\n    root_account = account.root_account? ? account : account.root_account\n    root_account.grading_period_groups.active\n  end\n\n  def self.for_course(context)\n    course_group = GradingPeriodGroup.find_by(course_id: context, workflow_state: :active)\n    return course_group if course_group.present?\n\n    account_group = context.enrollment_term.grading_period_group\n    (account_group.nil? || account_group.deleted?) ? nil : account_group\n  end\n\n  def recompute_scores_for_each_term(update_all_grading_period_scores, term_ids: nil)\n    terms = term_ids ? EnrollmentTerm.where(id: term_ids) : enrollment_terms.active\n\n    terms.find_each do |term|\n      term.recompute_course_scores_later(","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/grading_period_group.rb#L42-L78","documentation":"GradingPeriodGroup.for(account) returns all active grading period groups for a root account. It requires an actual Account instance (it calls root_account?/root_account on it), so any other object raises ArgumentError \"argument is not an Account\".","triggerScenarios":"Calling GradingPeriodGroup.for with a Course, an account_id integer, nil, or an Account-like wrapper instead of an Account record.","commonSituations":"Passing course instead of course.account, or an id from params into the method; common in grading-period controller/UI code.","solutions":["Pass the Account record: for a Course use course.account.","Resolve ids first with Account.find(id) before calling .for.","Use GradingPeriodGroup.for_course(context) when you have a course/context."],"exampleFix":"// before\nGradingPeriodGroup.for(course) # ArgumentError\n// after\nGradingPeriodGroup.for(course.account) # or for_course(course)","handlingStrategy":"type-guard","validationCode":"raise \"need an Account\" unless account.is_a?(Account)\nGradingPeriodGroup.for(account)","typeGuard":"def ensure_account(obj)\n  obj.is_a?(Account) ? obj : (obj.respond_to?(:account) ? obj.account : Account.find(obj))\nend","tryCatchPattern":"begin\n  GradingPeriodGroup.for(account)\nrescue ArgumentError\n  GradingPeriodGroup.for_course(course)\nend","preventionTips":["Pass Account records, not ids, Courses, or wrappers","Prefer for_course when working from a course context","Resolve params[:account_id] with Account.find before calling"],"tags":["type-error","guard-clause","grading-periods"],"backgroundTag":"type-mismatch","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"}