FrankYang0529 commented on code in PR #74119:
URL: https://github.com/apache/airflow/pull/74119#discussion_r4172360786


##########
go-sdk/airflow/dag.go:
##########
@@ -254,6 +264,12 @@ func (d *DagRef) Task(fn any, opts ...TaskOption) *TaskRef 
{
        }
        d.tasksByID[taskID] = task
        d.tasks = append(d.tasks, task)
+       // Inputs passes a task once per parameter it fills, so the same task 
can arrive twice. The
+       // edge is one either way. The task is new, so every edge to it is too: 
it carries no label
+       // to settle, and nothing downstream of it for an edge to close a cycle 
through.
+       for _, upstream := range upstreams {

Review Comment:
   Recording the Inputs edges here lets `b.Before(a)` fail after `b := 
dag.Task(B, airflow.Inputs(a))`. When I deleted this loop locally, only 
`TestInputsDeclaresAnEdgeInBothDirections` and 
`TestInputsDeclaresOneEdgePerTaskItRepeats` failed, and those two only assert 
what upstreams and downstreams contain., not the cycle. How about adding a case 
like:
   
   ```go
   func TestEdgeVerbsRejectACycleThroughAnInputsEdge(t *testing.T) {
        dag := Dag("etl")
        read := dag.Task(readRows)
        counted := dag.Task(countRows, Inputs(read))
        notified := orderedTask(t, dag, "notify")
        counted.Before(notified)
   
        assert.PanicsWithValue(t,
                `airflow.Node.Before: Dag "etl": an edge from task "countRows" 
to task "readRows" would `+
                        `close a cycle: readRows -> countRows -> readRows`,
                func() { counted.Before(read) },
        )
        assert.PanicsWithValue(t,
                `airflow.Node.After: Dag "etl": an edge from task "notify" to 
task "readRows" would `+
                        `close a cycle: readRows -> countRows -> notify -> 
readRows`,
                func() { read.After(notified) },
        )
        assert.Empty(t, read.upstreams)
        assertTasks(t, counted.downstreams, notified)
        assertTasks(t, notified.downstreams)
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to