apache/dolphinscheduler · error · IllegalArgumentException

"Cannot find task: " + post

Error message

"Cannot find task: " + post

What it means

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.

Source

Thrown at dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java:132

                    if (predecessors.containsKey(taskDefinition) || successors.containsKey(taskDefinition)) {
                        throw new IllegalArgumentException("The task " + taskDefinition + " is already exists");
                    }
                    predecessors.put(taskDefinition, new ArrayList<>());
                    successors.put(taskDefinition, new ArrayList<>());
                });
    }

    private void addTaskEdge(List<WorkflowTaskRelation> workflowTaskRelations) {
        for (WorkflowTaskRelation workflowTaskRelation : workflowTaskRelations) {
            long pre = workflowTaskRelation.getPreTaskCode();
            long post = workflowTaskRelation.getPostTaskCode();
            if (pre > 0 && post > 0) {

                if (!taskDefinitionCodeMap.containsKey(pre)) {
                    throw new IllegalArgumentException("Cannot find task: " + pre);
                }
                if (!taskDefinitionCodeMap.containsKey(post)) {
                    throw new IllegalArgumentException("Cannot find task: " + post);
                }
                TaskDefinition preTask = checkNotNull(taskDefinitionCodeMap.get(pre), "Cannot find task: " + pre);
                TaskDefinition postTask = checkNotNull(taskDefinitionCodeMap.get(post), "Cannot find task: " + pre);
                List<String> predecessorsTasks = predecessors.get(postTask.getName());
                if (predecessorsTasks.contains(preTask.getName())) {
                    throw new IllegalArgumentException("The task relation from " + preTask.getName() + " to "
                            + postTask.getName() + " is already exists");
                }
                predecessorsTasks.add(preTask.getName());

                List<String> successTasks = successors.get(preTask.getName());
                if (successTasks.contains(postTask.getName())) {
                    throw new IllegalArgumentException("The task relation from " + preTask.getName() + " to "
                            + postTask.getName() + " is already exists");
                }
                successTasks.add(postTask.getName());
            }

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Delete/repair orphaned relation rows whose postTaskCode has no matching task definition
  2. Load task definitions and relations from the same workflow-definition version/snapshot
  3. Validate relation endpoints against the task code set before constructing the graph
  4. Catch IllegalArgumentException during graph construction and report the workflow as having a broken definition

Example fix

// before
new WorkflowGraph(taskDefs, relations); // post code 888 not in taskDefs
// after
Set<Long> codes = taskDefs.stream().map(TaskDefinition::getCode).collect(Collectors.toSet());
if (relations.stream().anyMatch(r -> r.getPostTaskCode() > 0 && !codes.contains(r.getPostTaskCode()))) {
    throw new IllegalStateException("Workflow has relations pointing to undefined tasks");
}
WorkflowGraph g = new WorkflowGraph(taskDefs, relations);
Defensive patterns

Strategy: validation

Validate before calling

Set<Long> codes = taskDefinitions.stream().map(TaskDefinition::getCode).collect(Collectors.toSet());
List<WorkflowTaskRelation> broken = relations.stream()
        .filter(r -> r.getPostTaskCode() > 0 && !codes.contains(r.getPostTaskCode()))
        .collect(Collectors.toList());
if (!broken.isEmpty()) throw new IllegalStateException("Dangling post-task codes: " + broken);

Try / catch

try {
    WorkflowGraph graph = new WorkflowGraph(taskDefinitions, relations);
} catch (IllegalArgumentException e) {
    log.error("Relation target task missing: {}", e.getMessage());
    throw e;
}

Prevention

When it happens

Trigger: Constructing WorkflowGraph with a WorkflowTaskRelation whose getPostTaskCode() is > 0 and absent from the provided task definitions' codes.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/b2b3da8a9d44206a. Report an issue: GitHub.