instructure/canvas-lms · error · ImportError
account.errors.first.message
Error message
account.errors.first.message
What it means
After building/updating the Account record, add_account calls account.save; if ActiveRecord validation fails, ImportError is raised with the first validation error message from account.errors. The message text is dynamic — whatever Rails validation rejected the save (e.g. 'Name can't be blank', name length, circular parent chains enforced by custom validations).
Solutions
- Read the raised message — it is the Rails validation error and names the offending field.
- Fix the field cited (typically name or parent_account_id) in the SIS CSV row.
- Check for cycles: ensure the parent_account_id doesn't reference one of the account's own descendants.
- Run the account through Account.new(...).valid? in the Rails console to see all errors.
Example fix
// before
add_account('acct9', 'acct9_child', 'active', 'Cycle Account', nil) # circular parent
// after
add_account('acct9', 'root_parent', 'active', 'Cycle Account', nil) Defensive patterns
Strategy: try-catch
Validate before calling
candidate = root_account.all_accounts.new(sis_source_id: id, parent_account_id: parent&.id, name: name)
raise "invalid account: #{candidate.errors.full_messages.join(', ')}" unless candidate.valid? Try / catch
begin
importer.add_account(id, parent_id, status, name, integration_id)
rescue SIS::BaseImporter::ImportError => e
# e.message is the Rails validation error, e.g. "Name can't be blank"
logger.error("account #{id} failed validation: #{e.message}")
end Prevention
- Surface account.errors.full_messages in import reports
- Check for parent cycles before import
- Pre-validate names (presence/length) against Account model constraints
When it happens
Trigger: add_account produces an account that fails Account model validation on save — e.g. invalid name, parent chain creating a cycle, or a validation added by a plugin/patch.
Common situations: Empty names slipping through on updates of existing accounts; parent_account_id pointing at the account's own descendant creating a cycle; corrupted account data from earlier failed imports.
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
- A course did not pass validation
- A # user did not pass validation (user: # , # : # , error…
- A # did not pass validation (# : # , error: # )
- A # did not pass validation (# : # , error: # )
- An institutional tag category did not pass validation
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/32c78839402e120d.
Report an issue: GitHub.
Appendix: source
Thrown at lib/sis/account_importer.rb:118
@success_count += 1
accounts_to_set_sis_batch_ids << account.id unless account.sis_batch_id == @batch.try(:id)
return
end
account.sis_batch_id = @batch.id
update_account_associations = account.root_account_id_changed? || account.parent_account_id_changed?
if account.save
data = SisBatchRollBackData.build_data(sis_batch: @batch, context: account)
@roll_back_data << data if data
if update_account_associations
account.update_account_associations
account.clear_downstream_caches(:account_chain)
end
@success_count += 1
else
raise ImportError, account.errors.first.message
end
end
end
end
end
View on GitHub (pinned to 1c9f0bb801)