n8n-io/n8n · error · NotFoundError

Request to delete a user failed because the user to delete w

Error message

Request to delete a user failed because the user to delete was not found in DB

What it means

Returned by DELETE /users/:id when userRepository.findOne({id:idToDelete,relations:['role']}) yields null — the user to delete is not in the DB. HTTP 404. Distinct from the self-delete and owner-deletion guards; precedes the transferee checks.

Source

Thrown at packages/cli/src/controllers/users.controller.ts:243

		const { id: idToDelete } = req.params;

		if (req.user.id === idToDelete) {
			this.logger.debug(
				'Request to delete a user failed because it attempted to delete the requesting user',
				{ userId: req.user.id },
			);
			throw new BadRequestError('Cannot delete your own user');
		}

		const { transferId } = req.query;

		const userToDelete = await this.userRepository.findOne({
			where: { id: idToDelete },
			relations: ['role'],
		});

		if (!userToDelete) {
			throw new NotFoundError(
				'Request to delete a user failed because the user to delete was not found in DB',
			);
		}

		if (userToDelete.role.slug === GLOBAL_OWNER_ROLE.slug) {
			throw new ForbiddenError('Instance owner cannot be deleted.');
		}

		const personalProjectToDelete = await this.projectRepository.getPersonalProjectForUserOrFail(
			userToDelete.id,
		);

		if (transferId === personalProjectToDelete.id) {
			throw new BadRequestError(
				'Request to delete a user failed because the user to delete and the transferee are the same user',
			);
		}

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Check the user exists (GET /users/:id) before deleting.
  2. Treat a 404 as already-deleted and report success/idempotency to the operator if appropriate.
  3. Do not retry the same id.
Defensive patterns

Strategy: validation

Validate before calling

async function ensureDeleteTargetExists(id: string) {
  const r = await fetch(`/rest/users/${id}`);
  if (r.status === 404) return false;
  if (!r.ok) throw new Error(`lookup failed: ${r.status}`);
  return true;
}

Try / catch

try { await fetch(`/rest/users/${id}`, { method: 'DELETE' }); }
catch (e) { if (e.statusCode === 404) { /* already gone */ } else throw e; }

Prevention

When it happens

Trigger: DELETE /users/<unknown-or-deleted-id> issued by an admin with the user:delete scope; the id was never present or was already removed.

Common situations: Double-submit of a delete request; user already purged by another admin; id copied from a different environment.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/ad5ed7ab1a1b430a. Report an issue: GitHub.