apache/dolphinscheduler · error · ServiceException
50040
50040
Error message
Switch task definition version error
What it means
Thrown in switchVersion when taskDefinitionDao.queryByCode returns null or the task's projectCode differs from the requested projectCode. Either the task code is unknown or the task belongs to another project, so the version switch is refused to prevent cross-project modification.
Source
Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java:221
ReleaseState.ONLINE.getDescp(), taskCode);
throw new ServiceException(Status.WORKFLOW_DEFINE_STATE_ONLINE);
}
TaskDefinition taskDefinition = taskDefinitionDao.queryByCode(taskCode);
if (taskDefinition == null || projectCode != taskDefinition.getProjectCode()) {
log.error("Task definition does not exist, taskDefinitionCode:{}.", taskCode);
throw new ServiceException(Status.TASK_DEFINE_NOT_EXIST, String.valueOf(taskCode));
}
TaskDefinitionLog taskDefinitionUpdate =
taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, version);
taskDatasourcePermissionChecker.checkPermission(loginUser, Collections.singletonList(taskDefinitionUpdate));
taskSubWorkflowPermissionChecker.checkPermission(loginUser, Collections.singletonList(taskDefinitionUpdate));
taskDefinitionUpdate.setUserId(loginUser.getId());
taskDefinitionUpdate.setUpdateTime(new Date());
taskDefinitionUpdate.setId(taskDefinition.getId());
boolean switchSuccess = taskDefinitionDao.updateById(taskDefinitionUpdate);
if (!switchSuccess) {
log.error("Task definition version switch error, taskDefinitionCode:{}.", taskCode);
throw new ServiceException(Status.SWITCH_TASK_DEFINITION_VERSION_ERROR);
}
List<WorkflowTaskRelation> taskRelationList =
workflowTaskRelationDao.queryUpstreamByCode(projectCode, taskCode);
if (CollectionUtils.isNotEmpty(taskRelationList)) {
log.info(
"Task definition has upstream tasks, start handle them after switch task, taskDefinitionCode:{}.",
taskCode);
long workflowDefinitionCode = taskRelationList.get(0).getWorkflowDefinitionCode();
List<WorkflowTaskRelation> workflowTaskRelations =
workflowTaskRelationDao.queryByWorkflowDefinitionCode(workflowDefinitionCode);
updateDag(loginUser, workflowDefinitionCode, workflowTaskRelations,
Lists.newArrayList(taskDefinitionUpdate));
} else {
log.info(
"Task definition version switch complete, switch task version to {}, taskDefinitionCode:{}.",
version, taskCode);
}
}View on GitHub (pinned to 02eac45a1b)
Solutions
- Verify the task code and that it belongs to the given projectCode.
- Confirm the task definition was not deleted.
- Query the task list for the project to get the correct code.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java:221 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/5754481d2ed71a13.
Report an issue: GitHub.