Skip to content

Go SDK: add dag.If with Then and Else so native Dags can branch - #74075

Merged
jason810496 merged 2 commits into
apache:mainfrom
FrankYang0529:airflow-go-sdk-dag-if
Oct 3, 2026
Merged

jason810496 merged 2 commits into
apache:mainfrom
FrankYang0529:airflow-go-sdk-dag-if

Conversation

@FrankYang0529

@FrankYang0529 FrankYang0529 commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Implement Go SDK: Add dag.If with Then and Else.

  • dag.If(fn, opts...) returns an *airflow.IfRef and adds a task that runs the condition function fn. fn returns (bool, error). It follows the same rules as a function passed to dag.Task. IfRef.Then and IfRef.Else take the *airflow.TaskRef of the task to run on each side.
  • When fn returns true, the condition task skips the task from Else. When fn returns false, the condition task skips the task from Then. When fn returns an error, the condition task fails.
  • Before fn runs, the condition task writes {"skipped": []} to the skipmixin_key XCom. NotPreviouslySkippedDep reads that XCom when someone clears a skipped task. The Go runtime does not delete the XComs of earlier tries. Without the empty list, a list from an earlier try could skip a task that the current try did not skip. When the condition task skips a task, it first writes the task_id of that task to the skipmixin_key XCom and then sends SkipDownstreamTasks.

Was generative AI tooling used to co-author this PR?
  • Yes - Claude Code

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@FrankYang0529
FrankYang0529 marked this pull request as ready for review October 2, 2026 09:03

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks.
No major finding from me, here're the comments caught by the Claude reivew.

Comment thread go-sdk/airflow/if.go
Comment thread go-sdk/airflow/if.go
Comment thread go-sdk/airflow/if.go
Comment thread go-sdk/airflow/dag.go Outdated
Comment thread go-sdk/internal/bundle/task.go Outdated
Comment thread go-sdk/internal/bundle/task.go
Comment thread go-sdk/internal/bundle/task.go Outdated
Signed-off-by: PoAn Yang <payang@apache.org>
Signed-off-by: PoAn Yang <payang@apache.org>
@FrankYang0529
FrankYang0529 force-pushed the airflow-go-sdk-dag-if branch from 699f495 to f023213 Compare October 3, 2026 08:18

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jason810496
jason810496 merged commit bf558f6 into apache:main Oct 3, 2026
90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants