instructure/canvas-lms · error · ImportError

# # didn't exist for # # .

Error message

#{category_display_name} #{category_id} didn't exist for #{type_display_name(item_type)} #{item_id}.

What it means

Raised by find_category when no context resolved for the row and the root account's all_<category_type> lookup finds no non-deleted GroupCategory matching the sis_source_id. This is the account-wide variant of the missing-category error.

Solutions

  1. Correct the category id to an existing non-deleted one on the root account.
  2. Recreate or restore the category with that sis id before importing.
  3. Process group_categories.csv before groups.csv in the batch.
  4. Verify the batch's root account owns the category.

Example fix

# before
group_id,account_id,group_category_id,name,status
G101,A100,GC-404,Club,available   # GC-404 deleted/missing
# after
group_id,account_id,group_category_id,name,status
G101,A100,GC-1,Club,available
Defensive patterns

Strategy: validation

Validate before calling

cat = root_account.group_categories.where(deleted_at: nil).find_by(sis_source_id: category_id)
raise ArgumentError, "category #{category_id} not found on root account" unless cat

Try / catch

begin
  importer.add_group(gid, cat_id, acct_id, course_id, name, status)
rescue ImportError => e
  logger.warn("Category not found: #{e.message}")
end

Prevention

When it happens

Trigger: add_group where context resolution failed, then a group_category_id not matching any category with deleted_at: nil under the root account.

Common situations: Soft-deleted categories; category on a different root account/shard; typo'd category id; batch on the wrong root account.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at lib/sis/group_importer.rb:103

        category_display_name = if category_type.to_s == "differentiation_tag_category"
                                  "Differentiation Tag Set"
                                else
                                  "Group Category"
                                end

        category = nil
        if context
          category = context.send(category_type.to_s.pluralize).find_by(sis_source_id: category_id)
          unless category
            context_name = context.class.name.downcase
            raise ImportError, "#{category_display_name} #{category_id} didn't exist in #{context_name} #{context.sis_source_id} for #{type_display_name(item_type)} #{item_id}."
          end
        else
          method_name = "all_#{category_type.to_s.pluralize}"
          category = @root_account.send(method_name).find_by(deleted_at: nil, sis_source_id: category_id)
          unless category
            raise ImportError, "#{category_display_name} #{category_id} didn't exist for #{type_display_name(item_type)} #{item_id}."
          end
        end

        category
      end

      def save_and_process_memberships(item, item_type, status)
        if item.save
          data = SisBatchRollBackData.build_data(sis_batch: @batch, context: item)
          @roll_back_data << data if data

          if status == "deleted"
            gms = SisBatchRollBackData.build_dependent_data(
              sis_batch: @batch,
              contexts: item.group_memberships,
              updated_state: "deleted"
            )
            @roll_back_data.push(*gms) if gms

View on GitHub (pinned to 1c9f0bb801)