{"record":{"id":"075ee8226ecf4dad","repo":"apache/dolphinscheduler","slug":"50032","errorCode":"50032","errorMessage":"create workflow task relation error","messagePattern":"create workflow task relation error","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java","lineNumber":306,"sourceCode":"            throw new ServiceException(Status.CREATE_TASK_DEFINITION_ERROR);\n        }\n        int insertVersion =\n                processService.saveWorkflowDefine(loginUser, workflowDefinition, Boolean.TRUE, Boolean.TRUE);\n        if (insertVersion == 0) {\n            log.error(\"Save workflow definition error, workflowDefinitionCode:{}.\", workflowDefinition.getCode());\n            throw new ServiceException(Status.CREATE_WORKFLOW_DEFINITION_ERROR);\n        }\n        log.info(\"Save workflow definition complete, workflowDefinitionCode:{}, workflowDefinitionVersion:{}.\",\n                workflowDefinition.getCode(), insertVersion);\n        workflowDefinition.setVersion(insertVersion);\n        int insertResult = processService.saveTaskRelation(loginUser, workflowDefinition.getProjectCode(),\n                workflowDefinition.getCode(),\n                insertVersion, taskRelationList, taskDefinitionLogs, Boolean.TRUE);\n        if (insertResult != Constants.EXIT_CODE_SUCCESS) {\n            log.error(\n                    \"Save workflow task relations error, projectCode:{}, workflowDefinitionCode:{}, workflowDefinitionVersion:{}.\",\n                    workflowDefinition.getProjectCode(), workflowDefinition.getCode(), insertVersion);\n            throw new ServiceException(Status.CREATE_WORKFLOW_TASK_RELATION_ERROR);\n        }\n        log.info(\n                \"Save workflow task relations complete, projectCode:{}, workflowDefinitionCode:{}, workflowDefinitionVersion:{}.\",\n                workflowDefinition.getProjectCode(), workflowDefinition.getCode(), insertVersion);\n\n        saveWorkflowLineage(workflowDefinition.getProjectCode(), workflowDefinition.getCode(),\n                insertVersion, taskDefinitionLogs);\n        return workflowDefinition;\n    }\n\n    @Override\n    public void saveWorkflowLineage(long projectCode,\n                                    long workflowDefinitionCode,\n                                    int workflowDefinitionVersion,\n                                    List<TaskDefinitionLog> taskDefinitionLogList) {\n        List<WorkflowTaskLineage> workflowTaskLineageList = generateWorkflowLineageList(taskDefinitionLogList,\n                workflowDefinitionCode, workflowDefinitionVersion);\n","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java#L288-L324","documentation":"Thrown by createDagDefine when processService.saveTaskRelation returns a code other than Constants.EXIT_CODE_SUCCESS, meaning the workflow-task relation edges (DAG lineages between tasks) could not be saved after the definition was created.","triggerScenarios":"createWorkflowDefinition/doBatchOperateWorkflowDefinition with taskRelationJson referencing task codes/names inconsistent with the generated taskDefinitionLogs, or a DB failure inserting relation log rows.","commonSituations":"Hand-crafted taskRelationJson with wrong preTask/postTask names or missing tasks; relation list referencing tasks not in taskDefinitionJson; importing a DAG exported from a different version; DB transaction errors.","solutions":["Ensure taskRelationJson entries only reference task names/codes present in taskDefinitionJson and that preTasks form a valid DAG.","Regenerate taskRelationJson from the UI or a current-version export rather than hand-editing.","Check API logs for the exception inside saveTaskRelation and fix the DB issue; retry creation."],"exampleFix":"// before: relation references unknown task\n\"taskRelationJson\": \"[{\\\"preTaskName\\\":\\\"start\\\",\\\"postTaskName\\\":\\\"ghost_task\\\"}]\"\n// after: all endpoints exist in taskDefinitionJson\n\"taskRelationJson\": \"[{\\\"preTaskName\\\":\\\"start\\\",\\\"postTaskName\\\":\\\"a\\\"}]\" // 'a' defined above","handlingStrategy":"validation","validationCode":"Set<String> names = taskDefinitions.stream().map(TaskDefinition::getName).collect(Collectors.toSet());\nboolean valid = taskRelations.stream().allMatch(r ->\n    (r.getPreTaskName() == null || names.contains(r.getPreTaskName()))\n    && names.contains(r.getPostTaskName()));","typeGuard":null,"tryCatchPattern":"try {\n    workflowDefinitionService.createWorkflowDefinition(...);\n} catch (ServiceException e) {\n    if (e.getCode() == 50032) { /* fix taskRelationJson endpoints, retry */ }\n    else throw e;\n}","preventionTips":["Generate taskRelationJson from tooling that guarantees all referenced tasks exist.","Export/import DAGs only between compatible DolphinScheduler versions.","Never hand-edit relation JSON without re-validating against taskDefinitionJson."],"tags":["task-relation","dag","workflow-create","database-write"],"backgroundTag":"database-write-failed","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"}