{"record":{"id":"ad5ed7ab1a1b430a","repo":"n8n-io/n8n","slug":"request-to-delete-a-user-failed-because-the-user-t","errorCode":null,"errorMessage":"Request to delete a user failed because the user to delete was not found in DB","messagePattern":"Request to delete a user failed because the user to delete was not found in DB","errorType":"exception","errorClass":"NotFoundError","httpStatus":404,"severity":"error","filePath":"packages/cli/src/controllers/users.controller.ts","lineNumber":243,"sourceCode":"\t\tconst { id: idToDelete } = req.params;\n\n\t\tif (req.user.id === idToDelete) {\n\t\t\tthis.logger.debug(\n\t\t\t\t'Request to delete a user failed because it attempted to delete the requesting user',\n\t\t\t\t{ userId: req.user.id },\n\t\t\t);\n\t\t\tthrow new BadRequestError('Cannot delete your own user');\n\t\t}\n\n\t\tconst { transferId } = req.query;\n\n\t\tconst userToDelete = await this.userRepository.findOne({\n\t\t\twhere: { id: idToDelete },\n\t\t\trelations: ['role'],\n\t\t});\n\n\t\tif (!userToDelete) {\n\t\t\tthrow new NotFoundError(\n\t\t\t\t'Request to delete a user failed because the user to delete was not found in DB',\n\t\t\t);\n\t\t}\n\n\t\tif (userToDelete.role.slug === GLOBAL_OWNER_ROLE.slug) {\n\t\t\tthrow new ForbiddenError('Instance owner cannot be deleted.');\n\t\t}\n\n\t\tconst personalProjectToDelete = await this.projectRepository.getPersonalProjectForUserOrFail(\n\t\t\tuserToDelete.id,\n\t\t);\n\n\t\tif (transferId === personalProjectToDelete.id) {\n\t\t\tthrow new BadRequestError(\n\t\t\t\t'Request to delete a user failed because the user to delete and the transferee are the same user',\n\t\t\t);\n\t\t}\n","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/controllers/users.controller.ts#L225-L261","documentation":"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.","triggerScenarios":"DELETE /users/<unknown-or-deleted-id> issued by an admin with the user:delete scope; the id was never present or was already removed.","commonSituations":"Double-submit of a delete request; user already purged by another admin; id copied from a different environment.","solutions":["Check the user exists (GET /users/:id) before deleting.","Treat a 404 as already-deleted and report success/idempotency to the operator if appropriate.","Do not retry the same id."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"async function ensureDeleteTargetExists(id: string) {\n  const r = await fetch(`/rest/users/${id}`);\n  if (r.status === 404) return false;\n  if (!r.ok) throw new Error(`lookup failed: ${r.status}`);\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try { await fetch(`/rest/users/${id}`, { method: 'DELETE' }); }\ncatch (e) { if (e.statusCode === 404) { /* already gone */ } else throw e; }","preventionTips":["Verify existence with GET /users/:id first.","Treat 404 as idempotent already-deleted, not as a transient error.","Guard against double-submit of delete requests."],"tags":["users","delete","rest-api","not-found"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}