instructure/canvas-lms · error

invalid calculation_method: #

Error message

invalid calculation_method: #{value}

What it means

OutcomesAcademicBenchmarkImportApiController#parse_calculation_method validates the calculation_method against LearningOutcome.valid_calculation_method? and raises for anything unrecognized. Only the outcome calculation methods Canvas supports (e.g. decaying_average, n_mastery, latest, highest, average) are accepted.

Solutions

  1. Use one of LearningOutcome's valid calculation methods: decaying_average, n_mastery, latest, highest, average.
  2. Check LearningOutcome.valid_calculation_method?(value) or the CALCULATION_METHODS list before sending.
  3. Use the snake_case key, not the human-readable label.
  4. Confirm the target Canvas version supports the method (newer methods like average require recent versions).

Example fix

// before
{ calculation_method: "Decaying Average" }
// after
{ calculation_method: "decaying_average", calculation_int: 65 }
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError unless %w[decaying_average n_mastery latest highest average].include?(calculation_method)

Type guard

def valid_method?(v) = LearningOutcome.valid_calculation_method?(v)

Try / catch

begin
  import_outcomes(options)
rescue RuntimeError => e
  raise InvalidCalculationMethod, e.message if e.message.start_with?('invalid calculation_method:')
  raise
end

Prevention

When it happens

Trigger: Supplying calculation_method in the import options hash with a value outside the supported set, misspelled, or in wrong case (e.g. 'DecayingAverage', 'decay_avg').

Common situations: Copy-pasting calculation method names from other LMS docs; plugins adding custom methods not present on the target install; sending the method's display label instead of its key.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at app/controllers/outcomes_academic_benchmark_import_api_controller.rb:120

  def valid_options(hash)
    options = {}
    if hash.key? :calculation_method
      options[:calculation_method] = parse_calculation_method hash[:calculation_method]
      options[:calculation_int] = parse_calculation_int options[:calculation_method], hash[:calculation_int]
    end
    options[:mastery_points] = parse_int hash[:mastery_points] if hash.key? :mastery_points
    options[:points_possible] = parse_int hash[:points_possible] if hash.key? :points_possible
    unless hash[:ratings].nil?
      raise "ratings expected to be an array" unless hash[:ratings].is_a?(Array)

      options[:ratings] = hash[:ratings].map { |r| parse_rating(r) }
    end
    options
  end

  def parse_calculation_method(value)
    unless LearningOutcome.valid_calculation_method?(value)
      raise "invalid calculation_method: #{value}"
    end

    value
  end

  def parse_calculation_int(calc_method, value)
    int = value.nil? ? nil : parse_int(value)
    unless LearningOutcome.valid_calculation_int?(int, calc_method)
      raise "invalid calculation_int: #{value}"
    end

    int
  end

  def parse_rating(rating)
    if rating.nil? || !rating.is_a?(ActionController::Parameters)
      raise "invalid ratings value: #{rating}"
    end

View on GitHub (pinned to 1c9f0bb801)