apache/dolphinscheduler · error · IllegalArgumentException

"The task relation from " + pre + " to " + post + " is inval

Error message

"The task relation from " + pre + " to " + post + " is invalid"

What it means

A WorkflowTaskRelation is only meaningful if at least one endpoint is set: pre > 0 or post > 0. When both preTaskCode and postTaskCode are <= 0 the relation points nowhere, so addTaskEdge throws this IllegalArgumentException with the raw code values.

Source

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

                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());
            }

            if (pre <= 0 && post <= 0) {
                throw new IllegalArgumentException("The task relation from " + pre + " to " + post + " is invalid");
            }

        }
    }
}

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Filter out relations where pre <= 0 && post <= 0 before constructing the graph
  2. Find and delete zero-code rows in t_ds_workflow_task_relation
  3. Ensure relation creation always sets a valid postTaskCode (a task with no predecessor still has post > 0 and pre <= 0, which is legal)
  4. Catch IllegalArgumentException at construction to flag workflows with corrupt relation data

Example fix

// before
new WorkflowGraph(tasks, relations); // contains relation {pre:0, post:0}
// after
List<WorkflowTaskRelation> usable = relations.stream()
        .filter(r -> r.getPreTaskCode() > 0 || r.getPostTaskCode() > 0)
        .collect(Collectors.toList());
WorkflowGraph g = new WorkflowGraph(tasks, usable);
Defensive patterns

Strategy: validation

Validate before calling

boolean hasEmptyRelation = relations.stream()
        .anyMatch(r -> r.getPreTaskCode() <= 0 && r.getPostTaskCode() <= 0);
if (hasEmptyRelation) throw new IllegalStateException("Relation with both codes <= 0 present");

Try / catch

try {
    WorkflowGraph graph = new WorkflowGraph(taskDefinitions, relations);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("is invalid")) log.error("Zero-code relation row found");
    throw e;
}

Prevention

When it happens

Trigger: Constructing WorkflowGraph with a relation row where both getPreTaskCode() and getPostTaskCode() are 0 (or negative) — the default values of an unsaved/never-populated WorkflowTaskRelation.

Common situations: Relation rows inserted with default codes because the referenced task definitions failed to save; hand-written or generated relation JSON with placeholder zeros; deserialization of an empty relation object.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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