Add decorator to mark task as returning dag result#64563
Merged
Conversation
a935f2e to
ed11b50
Compare
kaxil
reviewed
Apr 2, 2026
kaxil
reviewed
Apr 2, 2026
kaxil
reviewed
Apr 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Task SDK ergonomics for marking a single TaskFlow task as the “DAG result”, supporting synchronous/inference-style execution patterns by allowing authors to either explicitly mark a task via a decorator or implicitly infer the result when returning an XComArg from a @dag function.
Changes:
- Introduces
@resultdecorator to mark a TaskFlow task as returning the DAG result (setsreturns_dag_result). - Updates
@dagdecorator factory to automatically calldag.add_result()when the decorated function returns a plain return-valueXComArg. - Adds/updates exports, docs, and tests for the new behavior; small refactor to centralize DAG-result validation.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| task-sdk/tests/task_sdk/definitions/test_dag.py | Adds tests for ignoring non-XCom returns and inferring DAG result from returned XComArg. |
| task-sdk/tests/task_sdk/definitions/decorators/test_result.py | New tests validating @result usage and behavior. |
| task-sdk/src/airflow/sdk/definitions/xcom_arg.py | Uses shared is_decorated_task() helper to validate map() callables. |
| task-sdk/src/airflow/sdk/definitions/decorators/init.pyi | Exposes result in typing stubs for decorators module. |
| task-sdk/src/airflow/sdk/definitions/decorators/init.py | Implements result() decorator and exports it. |
| task-sdk/src/airflow/sdk/definitions/dag.py | Adds _is_valid_dag_result() helper; auto-adds DAG result when @dag function returns a valid XComArg. |
| task-sdk/src/airflow/sdk/bases/decorator.py | Adds returns_dag_result flag propagation from decorator to created operator; adds is_decorated_task(). |
| task-sdk/src/airflow/sdk/init.pyi | Exposes result from airflow.sdk in typing stubs. |
| task-sdk/src/airflow/sdk/init.py | Adds result to public exports and lazy-import map. |
| airflow-core/docs/public-airflow-interface.rst | Documents airflow.sdk.result as part of the public interface. |
ed11b50 to
1de7834
Compare
1de7834 to
d35ec16
Compare
This ensures the flag is forwarded through .expand() and later .unmap() to the dynamically-created BaseOperator used on the runtime TI. This still does not mean result flag works for mapped tasks. Something will probably be returned, but I'm not sure what exactly. We'll still need to figure out what the exact behavior should be. This might involve special handling during return-value-XCom-push, or when the result value is aggregated in /wait API, or both. Not sure.
d35ec16 to
a8e9626
Compare
kaxil
reviewed
Jun 15, 2026
kaxil
approved these changes
Jun 23, 2026
cetingokhan
pushed a commit
to cetingokhan/airflow
that referenced
this pull request
Jun 24, 2026
This does not mean result flag works for mapped tasks yet. Something will probably be returned, but I'm not sure what exactly. We'll still need to figure out what the exact behavior should be. This might involve special handling during return-value-XCom-push, or when the result value is aggregated in /wait API, or both. Not sure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuing #51711 (comment)
This adds
@resultdecorator that can be used on top of any taskflow task instead of an explicitadd_resultcall (useful when you don’t have a reference to the dag object)@dag-decorated function,add_resultis called automatically on the created dag object.