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
- Filter out relations where pre <= 0 && post <= 0 before constructing the graph
- Find and delete zero-code rows in t_ds_workflow_task_relation
- Ensure relation creation always sets a valid postTaskCode (a task with no predecessor still has post > 0 and pre <= 0, which is legal)
- 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
- Filter default/unsaved WorkflowTaskRelation objects before saving
- Ensure relation creation always assigns a valid postTaskCode
- Clean zero-code rows from the relation table after failed saves
- Treat pre<=0 as 'no predecessor' (legal) but never allow both to be <=0
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
- "The task relation from " + preTask.getName() + " to " + pos
- 50032
- 50019
- WORKFLOW_NODE_HAS_CYCLE
- serious error: graph has cycle !
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/f98ba5bc6a9d0a4a.
Report an issue: GitHub.