{"record":{"id":"8a543d6e24f69850","repo":"instructure/canvas-lms","slug":"can-t-remove-yourself-user-id-user-id","errorCode":null,"errorMessage":"Can't remove yourself user_id '#{user_id}'","messagePattern":"Can't remove yourself user_id '#(.+?)'","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/sis/admin_importer.rb","lineNumber":87,"sourceCode":"        return if @batch.skip_deletes? && state == \"deleted\"\n\n        get_account(account_id)\n        raise ImportError, \"Invalid account_id given for admin\" unless @account\n\n        get_role(role_id, role)\n        raise ImportError, \"Invalid role '#{role}' for admin\" if role.present? && !@role\n        raise ImportError, \"Invalid role_id '#{role_id}' for admin\" if role_id.present? && !@role\n\n        the_root_account = root_account_from_id(root_account) if root_account\n        raise ImportError, \"Invalid or unknown user_id '#{user_id}' for admin\" if root_account && !the_root_account\n\n        the_root_account ||= @root_account\n\n        user = get_user(user_id, the_root_account)\n        raise ImportError, \"Invalid or unknown user_id '#{user_id}' for admin\" unless user\n\n        if state == \"deleted\" && user.id == @batch&.user_id && @account == @root_account\n          raise ImportError, \"Can't remove yourself user_id '#{user_id}'\"\n        end\n\n        create_or_find_admin(user, state)\n        user.clear_adminable_accounts_cache!\n        @success_count += 1\n      end\n\n      def create_or_find_admin(user, state)\n        case state\n        when \"active\"\n          admin = @account.account_users.where(user:, role: @role).first_or_initialize\n          admin.workflow_state = state\n        when \"deleted\"\n          admin = @account.account_users.where(user:, role: @role).where.not(sis_batch_id: nil).take\n          return unless admin\n\n          admin.current_user = @batch.user if @batch&.user\n          admin.workflow_state = state","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/sis/admin_importer.rb#L69-L105","documentation":"Raised by SIS::AdminImporter#process_admin when an import tries to delete (`status: 'deleted'`) an admin whose user is the same user running the batch, at the root account level. This self-protection prevents the import user from revoking their own admin privileges mid-import.","triggerScenarios":"Admin CSV row with status 'deleted' whose user_id equals @batch.user_id while @account equals @root_account — i.e. deleting the importing admin from the root account.","commonSituations":"Full admin syncs that regenerate the entire admin list and unintentionally omit the SIS operator's own membership; automation running under an admin account that is also managed by the same SIS feed.","solutions":["Remove the row (or change status to 'active') for the user running the import.","Run the SIS import under a dedicated service/admin account not managed by the same CSV.","Split the delete operation so the importing user's admin rights are removed manually by another admin.","Filter the CSV before import to skip rows where user_id == batch user."],"exampleFix":"// before\nprocess_admin(user_id: 'sis-operator-1', account_id: 'root', role: 'AccountAdmin', status: 'deleted') // self-delete\n// after\nprocess_admin(user_id: 'other-admin-2', account_id: 'root', role: 'AccountAdmin', status: 'deleted')","handlingStrategy":"try-catch","validationCode":"if status.to_s.downcase.strip == 'deleted' && user_id == batch_user_id && account_id == root_account_id\n  raise ArgumentError, 'refusing to delete the importing admin from the root account'\nend","typeGuard":null,"tryCatchPattern":"begin\n  importer.process_admin(user_id:, account_id:, role:, status: 'deleted')\nrescue SIS::ImportError => e\n  logger.warn(\"skipped self-delete: #{e.message}\")\nend","preventionTips":["Run SIS imports under a service account excluded from the admin sync CSV.","Filter rows where user_id equals the batch/import user before processing deletes.","Sync full admin lists carefully: never omit the operator account, or delete it out-of-band via another admin."],"tags":["sis-import","self-deletion-guard","admin-permissions"],"backgroundTag":"invalid-state-transition","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"}