{"record":{"id":"1667442f5111df92","repo":"apache/dolphinscheduler","slug":"10017-166744","errorCode":"10017","errorMessage":"tenant [{tenantId}] not exists","messagePattern":"tenant \\[(.+?)\\] not exists","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java","lineNumber":137,"sourceCode":"                           String userPassword,\n                           String email,\n                           int tenantId,\n                           String phone,\n                           String queue,\n                           int state) throws Exception {\n        if (!isAdmin(loginUser)) {\n            throw new ServiceException(Status.USER_NO_OPERATION_PERM);\n        }\n\n        // check all user params\n        String msg = this.checkUserParams(userName, userPassword, email, phone);\n        if (!StringUtils.isEmpty(msg)) {\n            throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, msg);\n        }\n\n        if (!checkTenantExists(tenantId)) {\n            log.warn(\"Tenant does not exist, tenantId:{}.\", tenantId);\n            throw new ServiceException(Status.TENANT_NOT_EXIST);\n        }\n\n        User user = createUser(userName, userPassword, email, tenantId, phone, queue, state);\n        log.info(\"User is created and id is {}.\", user.getId());\n        return user;\n    }\n\n    @Override\n    @Transactional\n    public User createUser(String userName,\n                           String userPassword,\n                           String email,\n                           int tenantId,\n                           String phone,\n                           String queue,\n                           int state) {\n        User user = new User();\n        Date now = new Date();","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java#L119-L155","documentation":"Thrown by UsersServiceImpl.createUser when the tenantId supplied in the create-user request does not match any tenant row in the database (checkTenantExists returns false). DolphinScheduler requires every user to belong to a valid tenant (a OS user used to run worker tasks), so creation is refused rather than leaving a dangling reference. It is a user-input/data-referential-integrity error, not a system failure.","triggerScenarios":"POST /users (createUser API) with a tenantId that was deleted, never created, or typed incorrectly; admin UI user form submitted with a stale tenant list; tenant dropped by another admin between loading the form and submitting.","commonSituations":"Admin deleted a tenant while the user-creation form was open; importing users via API automation with hard-coded tenantIds from another environment; fresh install where no tenants have been created yet.","solutions":["Query GET /tenants/list (or the t_ds_tenant table) and use an existing tenant id in the request","Create the missing tenant first via the tenant management API/UI, then retry user creation","If automating, fetch tenantId dynamically by tenant name instead of hard-coding","Verify you are operating against the intended environment's database (ids differ across installs)"],"exampleFix":"// before\napiClient.createUser(\"alice\", \"pwd\", \"a@b.c\", 42, ...); // hard-coded tenantId\n// after\nList<Tenant> tenants = apiClient.listTenants();\nint tenantId = tenants.stream().filter(t -> t.getTenantName().equals(\"dev\")).findFirst()\n    .orElseThrow(() -> new IllegalArgumentException(\"tenant 'dev' missing; create it first\")).getId();\napiClient.createUser(\"alice\", \"pwd\", \"a@b.c\", tenantId, ...);","handlingStrategy":"validation","validationCode":"// Java, before calling createUser\nboolean tenantExists = tenantsService.checkTenantExists(tenantId); // or query tenant list\nif (!tenantExists) {\n    throw new IllegalArgumentException(\"tenantId \" + tenantId + \" does not exist; create it first\");\n}\nusersService.createUser(userName, password, email, tenantId, phone, queue, state);","typeGuard":"// resolve and narrow to a validated tenant id\nInteger resolveTenantId(Integer tenantId, List<Tenant> tenants) {\n    return (tenantId != null && tenants.stream().anyMatch(t -> t.getId().equals(tenantId)))\n        ? tenantId : null; // null => refuse to call createUser\n}","tryCatchPattern":"try {\n    usersService.createUser(...);\n} catch (ServiceException e) {\n    if (e.getCode() == Status.TENANT_NOT_EXIST.getCode()) {\n        // recover: create tenant or pick valid one, then retry once\n    } else { throw e; }\n}","preventionTips":["Fetch tenant ids dynamically from the tenant list API instead of hard-coding","Create tenants as part of environment bootstrap before provisioning users","Re-validate tenantId if the form/session has been open a long time"],"tags":["tenant","user-management","validation","dolphinscheduler"],"backgroundTag":"entity-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"}