{"record":{"id":"b2b3da8a9d44206a","repo":"apache/dolphinscheduler","slug":"cannot-find-task-post","errorCode":null,"errorMessage":"\"Cannot find task: \" + post","messagePattern":"\"Cannot find task: \" \\+ post","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java","lineNumber":132,"sourceCode":"                    if (predecessors.containsKey(taskDefinition) || successors.containsKey(taskDefinition)) {\n                        throw new IllegalArgumentException(\"The task \" + taskDefinition + \" is already exists\");\n                    }\n                    predecessors.put(taskDefinition, new ArrayList<>());\n                    successors.put(taskDefinition, new ArrayList<>());\n                });\n    }\n\n    private void addTaskEdge(List<WorkflowTaskRelation> workflowTaskRelations) {\n        for (WorkflowTaskRelation workflowTaskRelation : workflowTaskRelations) {\n            long pre = workflowTaskRelation.getPreTaskCode();\n            long post = workflowTaskRelation.getPostTaskCode();\n            if (pre > 0 && post > 0) {\n\n                if (!taskDefinitionCodeMap.containsKey(pre)) {\n                    throw new IllegalArgumentException(\"Cannot find task: \" + pre);\n                }\n                if (!taskDefinitionCodeMap.containsKey(post)) {\n                    throw new IllegalArgumentException(\"Cannot find task: \" + post);\n                }\n                TaskDefinition preTask = checkNotNull(taskDefinitionCodeMap.get(pre), \"Cannot find task: \" + pre);\n                TaskDefinition postTask = checkNotNull(taskDefinitionCodeMap.get(post), \"Cannot find task: \" + pre);\n                List<String> predecessorsTasks = predecessors.get(postTask.getName());\n                if (predecessorsTasks.contains(preTask.getName())) {\n                    throw new IllegalArgumentException(\"The task relation from \" + preTask.getName() + \" to \"\n                            + postTask.getName() + \" is already exists\");\n                }\n                predecessorsTasks.add(preTask.getName());\n\n                List<String> successTasks = successors.get(preTask.getName());\n                if (successTasks.contains(postTask.getName())) {\n                    throw new IllegalArgumentException(\"The task relation from \" + preTask.getName() + \" to \"\n                            + postTask.getName() + \" is already exists\");\n                }\n                successTasks.add(postTask.getName());\n            }\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java#L114-L150","documentation":"Same validation as the pre-task check but applied to the relation's postTaskCode: when post > 0 it must exist in the graph's task code map, otherwise the edge target is unknown and this IllegalArgumentException is thrown with the missing post code.","triggerScenarios":"Constructing WorkflowGraph with a WorkflowTaskRelation whose getPostTaskCode() is > 0 and absent from the provided task definitions' codes.","commonSituations":"Orphaned relation rows after a task was deleted; relations loaded from a different workflow version than the task definitions; partially imported workflows where definitions were skipped but relations saved.","solutions":["Delete/repair orphaned relation rows whose postTaskCode has no matching task definition","Load task definitions and relations from the same workflow-definition version/snapshot","Validate relation endpoints against the task code set before constructing the graph","Catch IllegalArgumentException during graph construction and report the workflow as having a broken definition"],"exampleFix":"// before\nnew WorkflowGraph(taskDefs, relations); // post code 888 not in taskDefs\n// after\nSet<Long> codes = taskDefs.stream().map(TaskDefinition::getCode).collect(Collectors.toSet());\nif (relations.stream().anyMatch(r -> r.getPostTaskCode() > 0 && !codes.contains(r.getPostTaskCode()))) {\n    throw new IllegalStateException(\"Workflow has relations pointing to undefined tasks\");\n}\nWorkflowGraph g = new WorkflowGraph(taskDefs, relations);","handlingStrategy":"validation","validationCode":"Set<Long> codes = taskDefinitions.stream().map(TaskDefinition::getCode).collect(Collectors.toSet());\nList<WorkflowTaskRelation> broken = relations.stream()\n        .filter(r -> r.getPostTaskCode() > 0 && !codes.contains(r.getPostTaskCode()))\n        .collect(Collectors.toList());\nif (!broken.isEmpty()) throw new IllegalStateException(\"Dangling post-task codes: \" + broken);","typeGuard":null,"tryCatchPattern":"try {\n    WorkflowGraph graph = new WorkflowGraph(taskDefinitions, relations);\n} catch (IllegalArgumentException e) {\n    log.error(\"Relation target task missing: {}\", e.getMessage());\n    throw e;\n}","preventionTips":["Cascade-delete relations when task definitions are removed","Reconcile relation tables against definition tables after migrations/imports","Validate both endpoints of every relation in workflow-save logic","Never merge relations and definitions from different workflow versions"],"tags":["workflow-graph","task-relation","dangling-edge"],"backgroundTag":"resource-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"}