{"record":{"id":"32c78839402e120d","repo":"instructure/canvas-lms","slug":"account-errors-first-message","errorCode":null,"errorMessage":"account.errors.first.message","messagePattern":"account\\.errors\\.first\\.message","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/account_importer.rb","lineNumber":118,"sourceCode":"          @success_count += 1\n          accounts_to_set_sis_batch_ids << account.id unless account.sis_batch_id == @batch.try(:id)\n          return\n        end\n\n        account.sis_batch_id = @batch.id\n\n        update_account_associations = account.root_account_id_changed? || account.parent_account_id_changed?\n        if account.save\n          data = SisBatchRollBackData.build_data(sis_batch: @batch, context: account)\n          @roll_back_data << data if data\n          if update_account_associations\n            account.update_account_associations\n            account.clear_downstream_caches(:account_chain)\n          end\n\n          @success_count += 1\n        else\n          raise ImportError, account.errors.first.message\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":100,"sourceCodeEnd":124,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/account_importer.rb#L100-L124","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nadd_account('acct9', 'acct9_child', 'active', 'Cycle Account', nil) # circular parent\n// after\nadd_account('acct9', 'root_parent', 'active', 'Cycle Account', nil)","handlingStrategy":"try-catch","validationCode":"candidate = root_account.all_accounts.new(sis_source_id: id, parent_account_id: parent&.id, name: name)\nraise \"invalid account: #{candidate.errors.full_messages.join(', ')}\" unless candidate.valid?","typeGuard":null,"tryCatchPattern":"begin\n  importer.add_account(id, parent_id, status, name, integration_id)\nrescue SIS::BaseImporter::ImportError => e\n  # e.message is the Rails validation error, e.g. \"Name can't be blank\"\n  logger.error(\"account #{id} failed validation: #{e.message}\")\nend","preventionTips":["Surface account.errors.full_messages in import reports","Check for parent cycles before import","Pre-validate names (presence/length) against Account model constraints"],"tags":["sis","activerecord","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}