instructure/canvas-lms · error · InvalidDataError

Invalid fields for a group

Error message

Invalid fields for a group: %{invalid}

What it means

import_group rejects group objects that carry fields reserved for outcomes only: calculation_method, calculation_int, or ratings (OBJECT_ONLY_FIELDS). If any of these keys are present with a present? (non-blank) value, the group import aborts with this error listing the offending keys. Groups (LearningOutcomeGroup) have no mastery calculation, so these fields are meaningless there.

Solutions

  1. Remove calculation_method, calculation_int, and ratings from group objects.
  2. If your source rows share a schema, blank out these keys (nil or '') for rows where object_type is 'group'.
  3. Pre-validate rows and route: outcome-only fields imply the row should be imported as an 'outcome'.

Example fix

// before
{ object_type: 'group', title: 'Math', ratings: [{points: 3}] }
// after
{ object_type: 'group', title: 'Math' }
Defensive patterns

Strategy: validation

Validate before calling

OBJECT_ONLY = %i[calculation_method calculation_int ratings]
bad = OBJECT_ONLY.select { |k| group[k].present? }
raise ArgumentError, "group rows cannot set #{bad}" if bad.any?

Type guard

def group_only?(obj)
  obj.is_a?(Hash) && %i[calculation_method calculation_int ratings].none? { |k| obj[k].present? }
end

Try / catch

begin
  importer.import_object(object)
rescue Outcomes::Import::InvalidDataError => e
  Rails.logger.warn("bad group row #{object[:vendor_guid]}: #{e.message}")
end

Prevention

When it happens

Trigger: Calling import_object with object_type 'group' and e.g. {ratings: [{points: 3}]}, {calculation_method: 'highest'}, or {calculation_int: 79} set. Only non-blank values trigger it; empty strings/nil for these keys pass.

Common situations: Reusing one row/schema for both outcomes and groups and exporting all columns; CSV imports where the outcome-only columns are populated on group rows; client libraries that serialize a full outcome object even when importing a group.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at lib/outcomes/import.rb:77

      when "outcome"
        import_outcome(object)
      when "group"
        import_group(object)
      else
        raise InvalidDataError, I18n.t(
          'Invalid %{field}: "%{type}"',
          field: "object_type",
          type:
        )
      end
    end

    def import_group(group)
      invalid = group.keys.select do |k|
        group[k].present? && OBJECT_ONLY_FIELDS.include?(k)
      end
      if invalid.present?
        raise InvalidDataError, I18n.t(
          "Invalid fields for a group: %{invalid}",
          invalid: invalid.map(&:to_s).inspect
        )
      end

      group_context = context

      if group[:course_id].present?
        raise InvalidDataError, I18n.t("Cannot import to other courses") unless context.is_a?(Account)

        group_context = Course.find_by(id: group[:course_id])

        if group_context.nil?
          raise InvalidDataError, I18n.t(
            "Course with canvas id %{id} not found",
            id: group[:course_id]
          )
        end

View on GitHub (pinned to 1c9f0bb801)