{"record":{"id":"d1c5f1d58600578d","repo":"apache/dolphinscheduler","slug":"10143","errorCode":"10143","errorMessage":"delete tenant by id fail, for there are {count} workflow definitions using it","messagePattern":"delete tenant by id fail, for there are (.+?) workflow definitions using it","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java","lineNumber":235,"sourceCode":"    public void deleteTenantById(User loginUser, int id) throws Exception {\n\n        if (!canOperatorPermissions(loginUser, null, AuthorizationType.TENANT, TENANT_DELETE)) {\n            throw new ServiceException(Status.USER_NO_OPERATION_PERM);\n        }\n\n        Tenant tenant = tenantDao.queryDetailById(id);\n        if (Objects.isNull(tenant)) {\n            throw new ServiceException(Status.TENANT_NOT_EXIST);\n        }\n\n        List<WorkflowInstanceSummaryDto> workflowInstances = getWorkflowInstancesByTenant(tenant);\n        if (CollectionUtils.isNotEmpty(workflowInstances)) {\n            throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL, workflowInstances.size());\n        }\n\n        List<Schedule> schedules = scheduleDao.queryScheduleListByTenant(tenant.getTenantCode());\n        if (CollectionUtils.isNotEmpty(schedules)) {\n            throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL_DEFINES, schedules.size());\n        }\n\n        List<User> userList = userDao.queryUserListByTenant(tenant.getId());\n        if (CollectionUtils.isNotEmpty(userList)) {\n            throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL_USERS, userList.size());\n        }\n\n        if (!tenantDao.deleteById(id)) {\n            throw new ServiceException(Status.DELETE_TENANT_BY_ID_ERROR);\n        }\n\n        workflowInstanceDao.updateWorkflowInstanceByTenantCode(tenant.getTenantCode(), Constants.DEFAULT);\n    }\n\n    private List<WorkflowInstanceSummaryDto> getWorkflowInstancesByTenant(Tenant tenant) {\n        return workflowInstanceDao.queryByTenantCodeAndStatus(\n                tenant.getTenantCode(),\n                WorkflowExecutionStatus.NOT_TERMINAL_STATES);","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java#L217-L253","documentation":"Thrown in TenantServiceImpl.deleteTenantById when existing workflow definitions still use the tenant ({count} definitions). Referential-integrity guard: a tenant referenced by schedule/workflow definitions cannot be removed without first updating those definitions.","triggerScenarios":"Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java:235 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Update the workflow definitions/schedules to use a different tenant, then retry.","Delete the workflows that depend on this tenant if they are no longer needed.","List schedules by tenant code to identify what must change."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}