instructure/canvas-lms · error · ImportError

# # didn't exist in # # for # # .

Error message

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

What it means

Raised by find_category when a group_category_id/tag_set_id is given, a context (course or account) resolved, but no GroupCategory with that sis_source_id exists within that context. The message includes the category id, the context class name and sis id, and the item id.

Solutions

  1. Fix the category id to one defined in the same course/account context.
  2. Import group_categories.csv before groups.csv.
  3. Reference account-level categories only from account-scoped rows.
  4. Create the missing GroupCategory with the correct sis_source_id first.

Example fix

# before (GC-1 exists only on account, row is course-scoped)
group_id,course_id,group_category_id,name,status
G101,C200,GC-1,Study Group A,available
# after
group_id,course_id,group_category_id,name,status
G101,C200,CAT-C200-1,Study Group A,available
Defensive patterns

Strategy: validation

Validate before calling

ctx = root_account.all_courses.active.find_by(sis_source_id: course_id)
cat = ctx&.group_categories&.find_by(sis_source_id: category_id)
raise ArgumentError, "category #{category_id} missing in course #{course_id}" unless cat

Try / catch

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

Prevention

When it happens

Trigger: add_group/add_tag with a category id whose sis_source_id does not exist under the resolved course/account — e.g. a category defined at account level referenced from a course-scoped row.

Common situations: Category sis ids changed between terms; copying group CSVs across courses without remapping categories; importing group_categories.csv after groups.csv; cross-context id reuse.

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

Appendix: source

Thrown at lib/sis/group_importer.rb:97

        context
      end

      def find_category(category_id, context, category_type, item_type, item_id)
        return nil unless category_id.present?

        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"

View on GitHub (pinned to 1c9f0bb801)