Skip to content

Commit

Permalink
Use params instead of dag_run.conf in example (apache#40759)
Browse files Browse the repository at this point in the history
  • Loading branch information
jscheffl authored Jul 13, 2024
1 parent 5ae4e37 commit b95ea20
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions airflow/example_dags/example_params_trigger_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@

import datetime
from pathlib import Path
from typing import TYPE_CHECKING

from airflow.decorators import task
from airflow.models.dag import DAG
from airflow.models.param import Param
from airflow.models.param import Param, ParamsDict
from airflow.utils.trigger_rule import TriggerRule

if TYPE_CHECKING:
from airflow.models.dagrun import DagRun
from airflow.models.taskinstance import TaskInstance

with DAG(
dag_id=Path(__file__).stem,
dag_display_name="Params Trigger UI",
Expand All @@ -60,20 +55,18 @@

@task(task_id="get_names", task_display_name="Get names")
def get_names(**kwargs) -> list[str]:
ti: TaskInstance = kwargs["ti"]
dag_run: DagRun = ti.dag_run
if "names" not in dag_run.conf:
params: ParamsDict = kwargs["params"]
if "names" not in params:
print("Uuups, no names given, was no UI used to trigger?")
return []
return dag_run.conf["names"]
return params["names"]

@task.branch(task_id="select_languages", task_display_name="Select languages")
def select_languages(**kwargs) -> list[str]:
ti: TaskInstance = kwargs["ti"]
dag_run: DagRun = ti.dag_run
params: ParamsDict = kwargs["params"]
selected_languages = []
for lang in ["english", "german", "french"]:
if dag_run.conf.get(lang):
if params[lang]:
selected_languages.append(f"generate_{lang}_greeting")
return selected_languages

Expand Down

0 comments on commit b95ea20

Please sign in to comment.