{"record":{"id":"3115e29e0e07e3f7","repo":"n8n-io/n8n","slug":"target-user-not-found","errorCode":null,"errorMessage":"Target user not found","messagePattern":"Target user not found","errorType":"exception","errorClass":"NotFoundError","httpStatus":404,"severity":"error","filePath":"packages/cli/src/controllers/users.controller.ts","lineNumber":365,"sourceCode":"\t\tif (await this.provisioningService.isInstanceRoleManaged()) {\n\t\t\tthrow new ForbiddenError(\n\t\t\t\t'Instance roles are managed automatically and cannot be changed manually',\n\t\t\t);\n\t\t}\n\n\t\tconst { NO_ADMIN_ON_OWNER, NO_USER, NO_OWNER_ON_OWNER, CANNOT_CHANGE_OWN_ROLE } =\n\t\t\tUsersController.ERROR_MESSAGES.CHANGE_ROLE;\n\n\t\tif (req.user.id === id) {\n\t\t\tthrow new ForbiddenError(CANNOT_CHANGE_OWN_ROLE);\n\t\t}\n\n\t\tconst targetUser = await this.userRepository.findOne({\n\t\t\twhere: { id },\n\t\t\trelations: ['role'],\n\t\t});\n\t\tif (targetUser === null) {\n\t\t\tthrow new NotFoundError(NO_USER);\n\t\t}\n\n\t\tif (\n\t\t\treq.user.role.slug === GLOBAL_ADMIN_ROLE.slug &&\n\t\t\ttargetUser.role.slug === GLOBAL_OWNER_ROLE.slug\n\t\t) {\n\t\t\tthrow new ForbiddenError(NO_ADMIN_ON_OWNER);\n\t\t}\n\n\t\tif (\n\t\t\treq.user.role.slug === GLOBAL_OWNER_ROLE.slug &&\n\t\t\ttargetUser.role.slug === GLOBAL_OWNER_ROLE.slug\n\t\t) {\n\t\t\tthrow new ForbiddenError(NO_OWNER_ON_OWNER);\n\t\t}\n\n\t\tawait this.userService.changeUserRole(targetUser, payload);\n","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/controllers/users.controller.ts#L347-L383","documentation":"Returned by PATCH /users/:id/role when userRepository.findOne({id,relations:['role']}) returns null — the target user does not exist. Message is the NO_USER constant ('Target user not found') from UsersController.ERROR_MESSAGES.CHANGE_ROLE. HTTP 404. Fires after the self-role and provisioning guards.","triggerScenarios":"PATCH /users/<unknown-or-deleted-id>/role with a valid RoleChangeRequestDto; target id is not in the users table.","commonSituations":"Operating on a stale user list; user was deleted between page load and role change; cross-environment id mismatch.","solutions":["Verify the target user exists (GET /users/:id) before issuing the role change.","Do not retry the same id; treat 404 as terminal.","Refresh the admin user list and re-select the target."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"async function ensureTargetUserExists(id: string) {\n  const r = await fetch(`/rest/users/${id}`);\n  if (r.status === 404) throw new Error(`Target user ${id} not found; refresh the user list`);\n}","typeGuard":null,"tryCatchPattern":"try { await fetch(`/rest/users/${id}/role`, { method: 'PATCH', body }); }\ncatch (e) { if (e.statusCode === 404) { /* refresh list, reselect */ } else throw e; }","preventionTips":["Refresh the user list before role changes.","Do not retry the same unknown id.","Validate the id format (UUID) before sending."],"tags":["users","rbac","role-change","rest-api","not-found"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}