GitHub user aayostem edited a comment on the discussion: Using parameter to
select from dict prevents parsing
Helo @Chais, template strings cannot be used inside Python expressions during
DAG serialization. The templating happens at runtime, but the DAG
parsing/serialization happens before that.
what you can do it to use ti - task Instance- in a python function
`
from datetime import datetime
from airflow.decorators import dag, task
from airflow.models.param import Param
@dag(
"playground",
"Try things",
schedule=None,
start_date=datetime.now(),
params={
"selector": Param(
type="string",
title="Selector",
enum=["a", "b"],
default="a",
description="Pick one"
)
},
)
def playground():
values = {"a": "something", "b": "something else"}
@task.python
def task_print(**kwargs):
ti = kwargs['ti']
dag_run = kwargs['dag_run']
selector = dag_run.conf.get('selector', 'a')
value = values[selector]
print(value)
task_print()
playground_dag = playground()
`
i hope this help
GitHub link:
https://github.com/apache/airflow/discussions/58275#discussioncomment-14966932
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]