instructure/canvas-lms · error · ArgumentError

argument is not an Account

Error message

argument is not an Account

What it means

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".

Solutions

  1. Pass the Account record: for a Course use course.account.
  2. Resolve ids first with Account.find(id) before calling .for.
  3. Use GradingPeriodGroup.for_course(context) when you have a course/context.

Example fix

// before
GradingPeriodGroup.for(course) # ArgumentError
// after
GradingPeriodGroup.for(course.account) # or for_course(course)
Defensive patterns

Strategy: type-guard

Validate before calling

raise "need an Account" unless account.is_a?(Account)
GradingPeriodGroup.for(account)

Type guard

def ensure_account(obj)
  obj.is_a?(Account) ? obj : (obj.respond_to?(:account) ? obj.account : Account.find(obj))
end

Try / catch

begin
  GradingPeriodGroup.for(account)
rescue ArgumentError
  GradingPeriodGroup.for_course(course)
end

Prevention

When it happens

Trigger: Calling GradingPeriodGroup.for with a Course, an account_id integer, nil, or an Account-like wrapper instead of an Account record.

Common situations: Passing course instead of course.account, or an id from params into the method; common in grading-period controller/UI code.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/687c85846687ba53. Report an issue: GitHub.

Appendix: source

Thrown at app/models/grading_period_group.rb:60

    given do |user|
      root_account&.associated_user?(user)
    end
    can :read

    given do |user|
      (course || root_account).grants_right?(user, :manage)
    end
    can :update and can :delete

    given do |user|
      root_account&.grants_right?(user, :manage)
    end
    can :create
  end

  def self.for(account)
    raise ArgumentError, "argument is not an Account" unless account.is_a?(Account)

    root_account = account.root_account? ? account : account.root_account
    root_account.grading_period_groups.active
  end

  def self.for_course(context)
    course_group = GradingPeriodGroup.find_by(course_id: context, workflow_state: :active)
    return course_group if course_group.present?

    account_group = context.enrollment_term.grading_period_group
    (account_group.nil? || account_group.deleted?) ? nil : account_group
  end

  def recompute_scores_for_each_term(update_all_grading_period_scores, term_ids: nil)
    terms = term_ids ? EnrollmentTerm.where(id: term_ids) : enrollment_terms.active

    terms.find_each do |term|
      term.recompute_course_scores_later(

View on GitHub (pinned to 1c9f0bb801)