apache/dolphinscheduler · error · RuntimeException

User not found

Error message

User not found

What it means

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.

Source

Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java:462

    public void deleteTenantById(String userName, Integer tenantId) throws Exception {
        User user = usersService.queryUser(userName);
        tenantService.deleteTenantById(user, tenantId);
    }

    public User createUser(String userName,
                           String userPassword,
                           String email,
                           String phone,
                           String tenantCode,
                           String queue,
                           int state) throws IOException {
        return usersService.createUserIfNotExists(userName, userPassword, email, phone, tenantCode, queue, state);
    }

    public User queryUser(int id) {
        User user = usersService.queryUser(id);
        if (user == null) {
            throw new RuntimeException("User not found");
        }
        return user;
    }

    public User updateUser(String userName, String userPassword, String email, String phone, String tenantCode,
                           String queue, int state) throws Exception {
        return usersService.createUserIfNotExists(userName, userPassword, email, phone, tenantCode, queue, state);
    }

    public User deleteUser(String userName, int id) throws Exception {
        User user = usersService.queryUser(userName);
        usersService.deleteUserById(user, id);
        return usersService.queryUser(userName);
    }

    /**
     * Get single datasource by given datasource name. if type is not null,
     * it will return the datasource match the type.

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Verify the id exists (SELECT id FROM t_ds_user WHERE id=<id>) or list users in the UI
  2. Recreate the user if it was deleted, or use createUserIfNotExists
  3. Fix the caller to pass the correct/current user id or query by name via usersService.queryUser(userName)
  4. Catch the RuntimeException in gateway clients and fall back to user creation

Example fix

// before
User user = pythonGateway.queryUser(userId); // throws if absent
// after
User user = usersService.queryUser(userId);
if (user == null) {
    user = usersService.createUserIfNotExists(userName, pwd, email, phone, tenantCode, queue, 1);
}
Defensive patterns

Strategy: try-catch

Validate before calling

# caller side
user = users.get(user_id)
if user is None:
    user = create_user_if_not_exists(user_name, ...)
else:
    gateway.query_user(user['id'])

Type guard

// java
User getUserOrThrow(int id) {
    User u = usersService.queryUser(id);
    if (u == null) throw new RuntimeException("User not found: " + id);
    return u;
}

Try / catch

try {
    User user = pythonGateway.queryUser(id);
} catch (RuntimeException e) {
    if ("User not found".equals(e.getMessage())) {
        user = usersService.createUserIfNotExists(name, pwd, email, phone, tenant, queue, 1);
    } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: Scripts caching stale user ids after deletion; ids passed from an external system with different numbering; calling queryUser before initial user provisioning.

Understand the failure class

Background: "User not found", "Invalid user", and "does not exist": what missing-user lookup errors mean across Rocket.Chat, LiteLLM, Phabricator, rustfs, and pnpm — this error's family across 10 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/eeddb1c565cdb0f7. Report an issue: GitHub.