{"record":{"id":"eeddb1c565cdb0f7","repo":"apache/dolphinscheduler","slug":"user-not-found","errorCode":null,"errorMessage":"User not found","messagePattern":"User not found","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java","lineNumber":462,"sourceCode":"    public void deleteTenantById(String userName, Integer tenantId) throws Exception {\n        User user = usersService.queryUser(userName);\n        tenantService.deleteTenantById(user, tenantId);\n    }\n\n    public User createUser(String userName,\n                           String userPassword,\n                           String email,\n                           String phone,\n                           String tenantCode,\n                           String queue,\n                           int state) throws IOException {\n        return usersService.createUserIfNotExists(userName, userPassword, email, phone, tenantCode, queue, state);\n    }\n\n    public User queryUser(int id) {\n        User user = usersService.queryUser(id);\n        if (user == null) {\n            throw new RuntimeException(\"User not found\");\n        }\n        return user;\n    }\n\n    public User updateUser(String userName, String userPassword, String email, String phone, String tenantCode,\n                           String queue, int state) throws Exception {\n        return usersService.createUserIfNotExists(userName, userPassword, email, phone, tenantCode, queue, state);\n    }\n\n    public User deleteUser(String userName, int id) throws Exception {\n        User user = usersService.queryUser(userName);\n        usersService.deleteUserById(user, id);\n        return usersService.queryUser(userName);\n    }\n\n    /**\n     * Get single datasource by given datasource name. if type is not null,\n     * it will return the datasource match the type.","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java#L444-L480","documentation":"PythonGateway.queryUser(int id) delegates to usersService.queryUser and throws RuntimeException 'User not found' when no user with that id exists. Used by gateway consumers (e.g. PyDolphinScheduler) to resolve users by numeric id.","triggerScenarios":"Calling the gateway's queryUser with an id that has no row in t_ds_user - a deleted user, an id typo, or querying on a fresh installation.","commonSituations":"Scripts caching stale user ids after deletion; ids passed from an external system with different numbering; calling queryUser before initial user provisioning.","solutions":["Verify the id exists (SELECT id FROM t_ds_user WHERE id=<id>) or list users in the UI","Recreate the user if it was deleted, or use createUserIfNotExists","Fix the caller to pass the correct/current user id or query by name via usersService.queryUser(userName)","Catch the RuntimeException in gateway clients and fall back to user creation"],"exampleFix":"// before\nUser user = pythonGateway.queryUser(userId); // throws if absent\n// after\nUser user = usersService.queryUser(userId);\nif (user == null) {\n    user = usersService.createUserIfNotExists(userName, pwd, email, phone, tenantCode, queue, 1);\n}","handlingStrategy":"try-catch","validationCode":"# caller side\nuser = users.get(user_id)\nif user is None:\n    user = create_user_if_not_exists(user_name, ...)\nelse:\n    gateway.query_user(user['id'])","typeGuard":"// java\nUser getUserOrThrow(int id) {\n    User u = usersService.queryUser(id);\n    if (u == null) throw new RuntimeException(\"User not found: \" + id);\n    return u;\n}","tryCatchPattern":"try {\n    User user = pythonGateway.queryUser(id);\n} catch (RuntimeException e) {\n    if (\"User not found\".equals(e.getMessage())) {\n        user = usersService.createUserIfNotExists(name, pwd, email, phone, tenant, queue, 1);\n    } else { throw e; }\n}","preventionTips":["Prefer create_user_if_not_exists in pydolphinscheduler over raw lookups","Refresh cached user ids after user deletion","Query users by name instead of hard-coded numeric ids","Provision users before running gateway-dependent pipelines"],"tags":["python-gateway","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"}