instructure/canvas-lms · error · ImportError

# with sis id # didn't exist for # # .

Error message

#{id_type.to_s.sub("_id", "").titleize} with sis id #{id} didn't exist for #{type_display_name(type)} #{item_id}.

What it means

Raised by find_context when the course_id or account_id supplied for a row does not resolve to an existing active Course or Account under the root account by sis_source_id. The importer cannot attach the item to a nonexistent context, so it fails the row naming the context type, sis id, and item id.

Solutions

  1. Correct the course_id/account_id sis_source_id to an existing active record.
  2. Ensure the referenced context was imported first (courses.csv/accounts.csv in the same batch).
  3. Verify the course is active, not deleted or concluded.
  4. Confirm the sis id belongs to the same root account as the batch.

Example fix

# before
group_id,course_id,name,status
G101,C9999,Study Group A,available   # C9999 not found
# after
group_id,course_id,name,status
G101,C200,Study Group A,available
Defensive patterns

Strategy: validation

Validate before calling

ctx = root_account.all_courses.active.find_by(sis_source_id: course_id) ||
      root_account.all_accounts.active.find_by(sis_source_id: account_id)
raise ArgumentError, "context #{course_id || account_id} not found" unless ctx

Try / catch

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

Prevention

When it happens

Trigger: add_group called with an account_id or course_id whose sis_source_id matches no active account/course in the root account, including deleted/concluded courses.

Common situations: Course sis ids changed or courses deleted between exports; ids from a different root account/shard; typos in sis_source_id; groups.csv imported before courses.csv.

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

Appendix: source

Thrown at lib/sis/group_importer.rb:74

        return true if @batch.skip_deletes? && status =~ /deleted/i

        false
      end

      def find_context(id, id_type, type, item_id)
        context = nil
        cache = (id_type == :course_id) ? @courses_cache : @accounts_cache

        if id
          context = cache[id]
          context ||= if id_type == :course_id
                        @root_account.all_courses.active.find_by(sis_source_id: id)
                      else
                        @root_account.all_accounts.active.find_by(sis_source_id: id)
                      end

          unless context
            raise ImportError, "#{id_type.to_s.sub("_id", "").titleize} with sis id #{id} didn't exist for #{type_display_name(type)} #{item_id}."
          end

          cache[context.sis_source_id] = context if context
        end

        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

View on GitHub (pinned to 1c9f0bb801)