Budibase/budibase · error

Unable to delete self.

Error message

Unable to delete self.

What it means

bulkDelete iterates the requested user identifiers and rejects the whole operation if any target userId equals the currently authenticated user's id. This prevents a user from deleting their own account (which would break their session and tenant state). Called both directly by bulkDelete and via bulkUpdate flows that can delete.

Source

Thrown at packages/worker/src/api/controllers/global/users.ts:184

    // Need to get the _rev of the user doc to update
    const userById = await platform.users.getUserDoc(userByEmail.userId)
    await platform.users.updateUserDoc({
      ...userById,
      email,
      ssoId,
    })
    ctx.body = { message: "SSO support added." }
  } catch (err: any) {
    ctx.throw(err.status || 400, err?.message || err)
  }
}

const bulkDelete = async (
  users: Array<UserIdentifier>,
  currentUserId: string
) => {
  if (users.find(u => u.userId === currentUserId)) {
    throw new Error("Unable to delete self.")
  }
  return await userSdk.db.bulkDelete(users)
}

const bulkCreate = async (users: User[], groupIds: string[]) => {
  if (!env.SELF_HOSTED && users.length > MAX_USERS_UPLOAD_LIMIT) {
    throw new Error(
      "Max limit for upload is 1000 users. Please reduce file size and try again."
    )
  }
  return await userSdk.db.bulkCreate(users, groupIds)
}

export const bulkUpdate = async (
  ctx: Ctx<BulkUserRequest, BulkUserResponse>
) => {
  const currentUserId = ctx.user._id
  const input = ctx.request.body

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Remove the current user's id from the delete list before calling the API
  2. In the UI, disable/deselect the row representing the logged-in admin
  3. Delete other users first and have another admin remove the last one if needed
  4. Handle the error response and inform the user they cannot delete their own account

Example fix

// before
await api.bulkDelete(allUsers.map(u => ({ userId: u._id })))
// after
const deletable = allUsers.filter(u => u._id !== currentUser._id)
await api.bulkDelete(deletable.map(u => ({ userId: u._id })))
Defensive patterns

Strategy: validation

Validate before calling

if (users.some(u => u.userId === currentUserId)) {
  throw new Error("Cannot include the current user in a bulk delete")
}

Type guard

null

Try / catch

try {
  await api.bulkDelete(userIds)
} catch (e) {
  if (e.message.includes("Unable to delete self")) {
    notify("You cannot delete your own account")
  }
}

Prevention

When it happens

Trigger: Calling the bulk user delete endpoint (or a bulk update that routes into bulkDelete) with a payload that includes the current user's own userId among the users to delete.

Common situations: An admin selects 'all users' in a UI checkbox list including themselves; scripted cleanup that deletes every user in a tenant; stale client-side state where the admin's own row wasn't filtered out.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/834a6f4f37926696. Report an issue: GitHub.