Skip to content

Derive a mixed-language marker for Dags with task.stub - #71213

Draft
jason810496 wants to merge 1 commit into
apache:mainfrom
jason810496:feature/lang-sdk/mixed-language-dag-flag
Draft

Derive a mixed-language marker for Dags with task.stub#71213
jason810496 wants to merge 1 commit into
apache:mainfrom
jason810496:feature/lang-sdk/mixed-language-dag-flag

Conversation

@jason810496

@jason810496 jason810496 commented Aug 6, 2026

Copy link
Copy Markdown
Member

Why

A Lang-SDK artifact can play two roles that a Dag processor must treat oppositely, and nothing in the serialized Dag tells them apart:

Role Where the Dag is defined What the artifact contributes
Mixed-language Dag A Python file whose tasks are @task.stub Only the task implementations
Native Lang-SDK Dag The Go/Java source itself The whole Dag

For a native Dag the processor parses the artifact and the result is persisted. For a mixed-language Dag it must persist nothing: the Python Dag carrying the @task.stub tasks already owns that dag_id, so persisting the Lang-SDK side too would give conflicts.

How

The new is_mixed_language_dag flag at Dag level solves the problem.

  • Only the Lang SDK Dag can explicitly set the is_mixed_language_dag flag at Dag level argument.
  • For the Python Dag side, the is_mixed_language_dag field is a compute attribute that if there's any StubOperator in the Dag, the property will be true.
  • The Task SDK DAG gains nothing, a Python Dag can never set the is_mixed_language_dag flag.

The further mixed language Dag processing flow will be like:

  • JavaDagImporter don't emit those Dag with is_mixed_language_dag=True by default.
  • PythonDagImporter -> for all Dags which is_mixed_language_dag=True (the flag will be on if there's StubOperator in the Dag) -> validate the corresponding Java Dag structure (via TI.queue -> Coordinator -> JavaDagImporter(discover_mixed_language_dags=True) -> Java Dag structure) -> raise import error if there's validation error
  • and don't persist the Java side Dag structure.

Was generative AI tooling used to co-author this PR?

@jason810496 jason810496 self-assigned this Aug 6, 2026
@jason810496
jason810496 force-pushed the feature/lang-sdk/mixed-language-dag-flag branch from 2dff735 to 68c208e Compare August 6, 2026 05:48
A Lang-SDK artifact can either define a Dag natively or only supply the
implementations behind a Python Dag's @task.stub tasks. A Dag processor has to
treat those oppositely, persisting the first and discarding the second since the
Python Dag already owns that dag_id, and nothing in the serialized Dag told them
apart.

The flag is derived, never authored: a Python Dag reports it from the presence of
stub tasks, and neither the constructor nor attribute assignment can set it, so a
Dag cannot claim to be mixed-language without actually holding one.
@jason810496
jason810496 force-pushed the feature/lang-sdk/mixed-language-dag-flag branch from 68c208e to 8e0c2a4 Compare August 6, 2026 06:06
@jason810496 jason810496 removed the backport-to-v3-3-test Backport to v3-3-test label Aug 6, 2026
@jason810496 jason810496 added this to the Airflow 3.4.0 milestone Aug 6, 2026
@jason810496
jason810496 requested a review from uranusjr August 6, 2026 06:14
@jason810496 jason810496 added area:coordinator Coordinator: The interface to spawn Lang-SDK subprocesses area:serialization area:go-sdk area:ts-sdk area:java-sdk labels Aug 6, 2026
@jason810496
jason810496 marked this pull request as ready for review August 6, 2026 06:15
@jason810496 jason810496 changed the title Let a serialized Dag declare it only backs a Python Dag's stub tasks Derive a mixed-language marker for Dags with task.stub Aug 6, 2026
Always derived from the Dag's tasks, never author-set, so that a Lang-SDK Dag processor can
tell a Dag that merely backs stub tasks from one authored natively in that language.
"""
return any(task.operator_name == STUB_OPERATOR_NAME for task in self.task_dict.values())

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.

Operator name should not be used for logical conditions. Add a flag instead.

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