{"record":{"id":"24a95079db93da85","repo":"apache/dolphinscheduler","slug":"user-s-doesn-t-exist","errorCode":null,"errorMessage":"user %s doesn't exist","messagePattern":"user (.+?) doesn't exist","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/PermissionCheck.java","lineNumber":78,"sourceCode":"        this.processService = processService;\n        this.needChecks = needChecks;\n        this.userId = userId;\n        this.logger = logger;\n    }\n\n    /**\n     * check permission\n     *\n     * @throws ServiceException exception\n     */\n    public void checkPermission() throws ServiceException {\n        if (this.needChecks.length > 0) {\n\n            // get user type in order to judge whether the user is admin\n            User user = processService.getUserById(userId);\n            if (user == null) {\n                logger.error(\"User does not exist, userId:{}.\", userId);\n                throw new ServiceException(String.format(\"user %s doesn't exist\", userId));\n            }\n            if (user.getUserType() != UserType.ADMIN_USER) {\n                List<T> unauthorizedList = processService.listUnauthorized(userId, needChecks, authorizationType);\n                // if exist unauthorized resource\n                if (CollectionUtils.isNotEmpty(unauthorizedList)) {\n                    logger.error(\"User does not have {} permission for {}, userName:{}.\",\n                            authorizationType.getDescp(), unauthorizedList, user.getUserName());\n                    throw new ServiceException(String.format(\"user %s doesn't have permission of %s %s\",\n                            user.getUserName(), authorizationType.getDescp(), unauthorizedList.get(0)));\n                }\n            }\n        }\n    }\n\n}\n","sourceCodeStart":60,"sourceCodeEnd":94,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/permission/PermissionCheck.java#L60-L94","documentation":"PermissionCheck.checkPermission looks up the User by userId via processService.getUserById before evaluating authorization. If no user row matches the id it throws a ServiceException 'user <id> doesn't exist'. Called from guarded API paths such as releasing a task definition.","triggerScenarios":"An API request (e.g. releaseTaskDefinition) passes a userId with no matching record in t_ds_user - the user was deleted while the caller still holds their id, or an id of 0/invalid value is passed.","commonSituations":"Stale client sessions after an admin deleted the user; manually forged requests with arbitrary ids; data migration leaving orphaned ids in request payloads.","solutions":["Log in again / refresh the session so a valid userId is used","Verify the user exists: query t_ds_user for the id (SELECT * FROM t_ds_user WHERE id=<id>)","If users were deleted, clean up references (schedules, releases, tokens) pointing to the removed id","Recreate the deleted user account if historical references must stay valid"],"exampleFix":"// before\npermissionCheck.checkPermission(userId, ...);\n// after: guard on caller side\nUser user = usersService.queryUser(userId);\nif (user == null) { throw new ServiceException(\"user \" + userId + \" doesn't exist\"); }\npermissionCheck.checkPermission(userId, ...);","handlingStrategy":"validation","validationCode":"// before invoking guarded API\nUser user = usersService.queryUser(userId);\nif (user == null) {\n    throw new ServiceException(\"user \" + userId + \" doesn't exist - re-login\");\n}","typeGuard":"boolean userExists(int userId) {\n    return userId > 0 && processService.getUserById(userId) != null;\n}","tryCatchPattern":"try {\n    permissionCheck.checkPermission(userId, needChecks, authorizationType);\n} catch (ServiceException e) {\n    if (e.getMessage().endsWith(\"doesn't exist\")) {\n        log.warn(\"stale userId {}, forcing re-authentication\", userId);\n        throw new ServiceStatusHttpException(Status.USER_NOT_EXIST, e);\n    }\n    throw e;\n}","preventionTips":["Invalidate sessions/tokens when a user is deleted","Never accept userId=0 or negative ids from clients","Clean up orphaned references after user deletion","Re-fetch the user from DB on each privileged request rather than caching"],"tags":["authorization","user-management"],"backgroundTag":"user-not-found","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}