instructure/canvas-lms · error · ImportError

Account with id "# " didn't exist for # #

Error message

Account with id "#{account_id}" didn't exist for #{type_display} #{sis_id}

What it means

find_context looks up an Account by sis_source_id (@root_account.all_accounts.active.find_by). When the account_id in the row matches no active account under the root account, the importer has no context to attach the group category/tag to and raises ImportError.

Solutions

  1. Verify the account_id matches an existing account's sis_source_id under the importing root account (check accounts table).
  2. Re-export the CSV from the current Canvas state so IDs are fresh.
  3. If the account was intentionally deleted, remove or correct dependent rows in the import.
  4. Check the account is active (not soft-deleted), since lookup uses .active.

Example fix

// before
gc-1,Math Groups,ACCT-TYPO,,active
// after (existing sis_source_id)
gc-1,Math Groups,ACCT-123,,active
Defensive patterns

Strategy: try-catch

Validate before calling

unless Account.active.where(root_account_id: root_account.id, sis_source_id: account_id).exists?
  raise ArgumentError, "account #{account_id} not found under root account"
end

Try / catch

begin
  importer.add_group_category(sis_id, account_id, nil, name, status)
rescue SIS::GroupCategoryImporter::ImportError => e
  if e.message =~ /Account with id/ then skip_row(sis_id, e.message)
  else raise end
end

Prevention

When it happens

Trigger: add_group_category / add_group / add_tag / add_differentiation_tag_set called with an account_id whose sis_source_id does not exist, is soft-deleted, or belongs to a different root account.

Common situations: Stale SIS data: the account was deleted or its sis_source_id renamed after the CSV was generated; cross-instance imports where IDs from another Canvas instance are used; typo in the account's SIS ID; account is inactive ('active' scope filters it out).

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — 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/57a80e37ada06fb6. Report an issue: GitHub.

Appendix: source

Thrown at lib/sis/group_category_importer.rb:63

        raise ImportError, "No sis_id given for a #{type_display}" if sis_id.blank?
        raise ImportError, "No name given for #{type_display} #{sis_id}" if name.blank?
        raise ImportError, "No status given for #{type_display} #{sis_id}" if status.blank?
        raise ImportError, "Improper status \"#{status}\" for #{type_display} #{sis_id}, skipping" unless /\A(active|deleted)/i.match?(status)
        return true if @batch.skip_deletes? && status =~ /deleted/i

        false
      end

      def find_context(account_id, course_id, sis_id, type_display)
        context = nil
        if account_id && course_id
          raise ImportError, "Only one context is allowed and both course_id and account_id where provided for #{type_display} #{sis_id}."
        end

        if account_id
          context = @accounts_cache[account_id]
          context ||= @root_account.all_accounts.active.find_by(sis_source_id: account_id)
          raise ImportError, "Account with id \"#{account_id}\" didn't exist for #{type_display} #{sis_id}" unless context

          @accounts_cache[context.sis_source_id] = context
        end

        if course_id
          context = @courses_cache[course_id]
          context ||= @root_account.all_courses.active.find_by(sis_source_id: course_id)
          raise ImportError, "Course with id \"#{course_id}\" didn't exist for #{type_display} #{sis_id}" unless context

          @courses_cache[context.sis_source_id] = context
        elsif course_id.nil? && type_display == "differentiation tag set"
          raise ImportError, "No course_id given for #{type_display} #{sis_id}"
        end

        context || @root_account
      end

      def check_context_movement(category, context, sis_id, type_display)

View on GitHub (pinned to 1c9f0bb801)