instructure/canvas-lms · error · ImportError

A # did not pass validation (# : # , error: # )

Error message

A #{type_display} did not pass validation (#{type_display}: #{sis_id}, error: #{category.errors.full_messages.join(",")})

What it means

save_category saves the built GroupCategory / DifferentiationTagCategory model; if ActiveRecord validation fails (category.errors), the importer raises ImportError with the model's full_messages so the SIS row author can correct the offending data.

Solutions

  1. Read the embedded error message — it lists the exact model validation failures.
  2. Rename the category in the CSV if it collides with an existing category in the same course.
  3. Shorten the name to fit the database column limit.
  4. Check the context resolution: if the sis_id unexpectedly maps to a different existing category, its stale attributes may be failing validation.

Example fix

// before (duplicate name in same course)
gc-2,Math Groups,,COURSE-42,active  # 'Math Groups' already exists in COURSE-42
// after
gc-2,Math Groups B,,COURSE-42,active
Defensive patterns

Strategy: try-catch

Validate before calling

existing = course.group_categories.where(name: category_name).exists?
raise ArgumentError, "category name '#{category_name}' already exists in course" if existing

Try / catch

begin
  importer.add_group_category(sis_id, acct_id, course_id, name, status)
rescue SIS::GroupCategoryImporter::ImportError => e
  if e.message =~ /did not pass validation/ then report(sis_id, e.message)
  else raise end
end

Prevention

When it happens

Trigger: add_group_category or add_differentiation_tag_set builds a category whose attributes fail model validations — e.g., duplicate category name within the same course context, name too long, or nil required attributes that slipped past row-level checks.

Common situations: Two rows in the same import (or an existing UI-created category) sharing a name in the same course; CSV names exceeding the column length limit; special/whitespace-only names failing presence or format validations.

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/a1060b993c408111. Report an issue: GitHub.

Appendix: source

Thrown at lib/sis/group_category_importer.rb:109

      def apply_status(category, status)
        case status
        when /active/i
          category.deleted_at = nil
        when /deleted/i
          category.deleted_at = Time.zone.now
        end
      end

      def save_category(category, sis_id, type_display)
        if category.save
          data = build_data(category)
          @roll_back_data << data if data
          @success_count += 1
          true
        else
          msg = "A #{type_display} did not pass validation (#{type_display}: #{sis_id}, error: "
          msg += category.errors.full_messages.join(",") + ")"
          raise ImportError, msg
        end
      end

      def add_group_category(sis_id, account_id, course_id, category_name, status)
        return if invalid_category?(sis_id, category_name, status, "group category")

        context = find_context(account_id, course_id, sis_id, "group category")
        gc = @root_account.all_group_categories.find_by(sis_source_id: sis_id)

        check_context_movement(gc, context, sis_id, "group category")

        gc ||= context.group_categories.new
        gc.name = category_name
        gc.context = context
        gc.root_account_id = @root_account.id
        gc.sis_source_id = sis_id
        gc.sis_batch_id = @batch.id

View on GitHub (pinned to 1c9f0bb801)