{"record":{"id":"6e2422d3eae89075","repo":"apache/dolphinscheduler","slug":"tenant-s-not-exists","errorCode":null,"errorMessage":"Tenant: [%s] not exists","messagePattern":"Tenant: \\[(.+?)\\] not exists","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/TenantExistValidator.java","lineNumber":43,"sourceCode":"\n/**\n * This validator is used to validate whether the tenant exists.\n * <p> If the tenant does not exist, an {@link IllegalArgumentException} will be thrown. </p>\n */\n@Slf4j\n@Component\npublic class TenantExistValidator implements IValidator<String> {\n\n    private final TenantDao tenantDao;\n\n    public TenantExistValidator(TenantDao tenantDao) {\n        this.tenantDao = tenantDao;\n    }\n\n    @Override\n    public void validate(String tenantCode) {\n        if (!tenantDao.queryByCode(tenantCode).isPresent()) {\n            throw new IllegalArgumentException(String.format(\"Tenant: [%s] not exists\", tenantCode));\n        }\n    }\n}\n","sourceCodeStart":25,"sourceCodeEnd":47,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/TenantExistValidator.java#L25-L47","documentation":"TenantExistValidator is a javax validation constraint validator used on API request DTOs whose fields carry @TenantExist (or similar). Its validate() looks up the tenant code via tenantDao.queryByCode; if no tenant is present in the database it throws IllegalArgumentException with 'Tenant: [code] not exists'. This ensures API operations referencing a tenant (e.g. user creation, resource upload) target an actual tenant row.","triggerScenarios":"Submitting any validated request whose tenantCode field (annotated with the tenant-existence constraint) references a tenant code that has no matching row in t_ds_tenant.","commonSituations":"Typo in tenant code in API payload or UI config; tenant deleted after a user/config was created referencing it; multi-cluster setups where the API server connects to a DB that lacks the tenant; copying example payloads with placeholder tenant codes.","solutions":["Query the tenants page (or t_ds_tenant) and use the exact existing tenant code in the request.","Create the missing tenant first via the tenant-management API, then retry the request.","If the tenant was deleted, clean up or reassign users/resources that reference the stale tenant code."],"exampleFix":"// before\n{\"user_name\":\"alice\",\"tenant_code\":\"prod_tennat\"}   // typo\n// after\n{\"user_name\":\"alice\",\"tenant_code\":\"prod_tenant\"}   // code exists in t_ds_tenant","handlingStrategy":"validation","validationCode":"// verify tenant exists before the validated API call\nTenant tenant = tenantMapper.queryByTenantCode(tenantCode);\nif (tenant == null) {\n    throw new IllegalStateException(\"Tenant not found: \" + tenantCode);\n}","typeGuard":"function isKnownTenant(code, tenantCodes) {\n  return typeof code === 'string' && tenantCodes.includes(code);\n}","tryCatchPattern":"try {\n    // call API with tenantCode\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Tenant:\")) {\n        // list tenants and pick a valid code, or create the tenant first\n    } else throw e;\n}","preventionTips":["Keep tenant codes in a checked dropdown sourced from the tenants API, not free text","Clean up or reassign references when deleting tenants","Verify the API server points at the same DB/cluster where the tenant exists"],"tags":["tenant","validation","entity-not-found"],"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-14T05:17:10.506Z"}