{"record":{"id":"0fc7513ad7318564","repo":"apache/dolphinscheduler","slug":"10017","errorCode":"10017","errorMessage":"tenant [{tenantCode}] 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/TenantServiceImpl.java","lineNumber":108,"sourceCode":"            throw new ServiceException(Status.TENANT_FULL_NAME_TOO_LONG_ERROR);\n        } else if (!RegexUtils.isValidLinuxUserName(tenant.getTenantCode())) {\n            throw new ServiceException(Status.CHECK_OS_TENANT_CODE_ERROR);\n        } else if (checkTenantExists(tenant.getTenantCode())) {\n            throw new ServiceException(Status.OS_TENANT_CODE_EXIST, tenant.getTenantCode());\n        }\n    }\n\n    /**\n     * Check tenant update object valid or not\n     *\n     * @param existsTenant The exists queue object\n     * @param updateTenant The queue object want to update\n     */\n    private void updateTenantValid(Tenant existsTenant, Tenant updateTenant) throws ServiceException {\n        // Check the exists tenant\n        if (Objects.isNull(existsTenant)) {\n            log.error(\"Tenant does not exist.\");\n            throw new ServiceException(Status.TENANT_NOT_EXIST);\n        }\n        // Check the update tenant parameters\n        else if (StringUtils.isEmpty(updateTenant.getTenantCode())) {\n            throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, updateTenant.getTenantCode());\n        } else if (StringUtils.length(updateTenant.getTenantCode()) > TENANT_FULL_NAME_MAX_LENGTH) {\n            throw new ServiceException(Status.TENANT_FULL_NAME_TOO_LONG_ERROR);\n        } else if (!RegexUtils.isValidLinuxUserName(updateTenant.getTenantCode())) {\n            throw new ServiceException(Status.CHECK_OS_TENANT_CODE_ERROR);\n        } else if (!Objects.equals(existsTenant.getTenantCode(), updateTenant.getTenantCode())\n                && checkTenantExists(updateTenant.getTenantCode())) {\n            throw new ServiceException(Status.OS_TENANT_CODE_EXIST, updateTenant.getTenantCode());\n        }\n    }\n\n    /**\n     * create tenant\n     *\n     * @param loginUser login user","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java#L90-L126","documentation":"Status.TENANT_NOT_EXIST from updateTenantValid: the tenant record being updated (existsTenant) is null — the tenant id supplied to updateTenant does not correspond to any existing tenant. Updates operate on an already-loaded tenant; without it the operation cannot proceed.","triggerScenarios":"PUT /tenants/{id} with an id that was deleted, never existed, or belongs to another environment; stale UI page holding a tenant deleted in another tab.","commonSituations":"Scripts caching tenant ids across cleanup jobs; environments cloned without the tenants table contents; users editing a tenant deleted by an admin concurrently.","solutions":["Verify the tenant id via GET /tenants list and use a current id.","Refresh the UI page to drop stale tenant references.","Recreate the missing tenant if it was deleted unintentionally, then update.","Fix environment sync so tenants exist in the target instance before running update scripts."],"exampleFix":"// before\nint id = 42; // cached from last week\ntenantService.updateTenant(loginUser, id, \"newcode\", \"desc\", 1, 1);\n// after\nInteger id = tenantList.stream().filter(t -> t.getTenantCode().equals(\"oldcode\")).findFirst()\n        .map(Tenant::getId).orElse(null);\nif (id != null) tenantService.updateTenant(loginUser, id, \"newcode\", \"desc\", 1, 1);","handlingStrategy":"validation","validationCode":"boolean tenantExists = tenantService.listAllTenants(loginUser).stream()\n        .anyMatch(t -> t.getId() == tenantId);\nif (!tenantExists) {\n    throw new IllegalArgumentException(\"tenant id \" + tenantId + \" does not exist; refresh from tenant list\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    tenantService.updateTenant(loginUser, tenantId, code, desc, queueId, 1);\n} catch (ServiceException e) {\n    if (e.getCode() == 10017) { /* stale id: re-query tenant list and retry with current id */ }\n}","preventionTips":["Always fetch fresh tenant ids from the list API before updates","Refresh UI pages after other admins delete tenants","Keep tenant data in sync across cloned environments","Don't cache tenant ids across cleanup/migration jobs"],"tags":["tenant","not-found","stale-reference","api"],"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"}