Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TriggeredDagRunOperator triggered link #40336

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions airflow/operators/trigger_dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ class TriggerDagRunLink(BaseOperatorLink):
name = "Triggered DAG"

def get_link(self, operator: BaseOperator, *, ti_key: TaskInstanceKey) -> str:
# Fetch the correct execution date for the triggerED dag which is
# Fetch the correct dag_run_id for the triggerED dag which is
# stored in xcom during execution of the triggerING task.
when = XCom.get_value(ti_key=ti_key, key=XCOM_LOGICAL_DATE_ISO)
query = {"dag_id": cast(TriggerDagRunOperator, operator).trigger_dag_id, "base_date": when}
triggered_dag_run_id = XCom.get_value(ti_key=ti_key, key=XCOM_RUN_ID)
query = {
"dag_id": cast(TriggerDagRunOperator, operator).trigger_dag_id,
"dag_run_id": triggered_dag_run_id,
}
return build_airflow_url_with_query(query)


Expand Down Expand Up @@ -218,8 +221,9 @@ def execute(self, context: Context):
raise e
if dag_run is None:
raise RuntimeError("The dag_run should be set here!")
# Store the execution date from the dag run (either created or found above) to
# Store the run id from the dag run (either created or found above) to
# be used when creating the extra link on the webserver.
# TODO: Logical date as xcom stored only for backwards compatibility. Remove in Airflow 3.0
ti = context["task_instance"]
ti.xcom_push(key=XCOM_LOGICAL_DATE_ISO, value=dag_run.logical_date.isoformat())
ti.xcom_push(key=XCOM_RUN_ID, value=dag_run.run_id)
Expand Down
4 changes: 2 additions & 2 deletions tests/operators/test_trigger_dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def assert_extra_link(self, triggered_dag_run, triggering_task, session):
"""
Asserts whether the correct extra links url will be created.

Specifically it tests whether the correct dag id and date are passed to
Specifically it tests whether the correct dag id and run id are passed to
the method which constructs the final url.
Note: We can't run that method to generate the url itself because the Flask app context
isn't available within the test logic, so it is mocked here.
Expand All @@ -111,7 +111,7 @@ def assert_extra_link(self, triggered_dag_run, triggering_task, session):
args, _ = mock_build_url.call_args
expected_args = {
"dag_id": triggered_dag_run.dag_id,
"base_date": triggered_dag_run.logical_date.isoformat(),
"dag_run_id": triggered_dag_run.run_id,
}
assert expected_args in args

Expand Down