GitHub user Chais closed a discussion: Using parameter to select from dict 
prevents parsing

I have a workflow where I want to run a backup process from an active machine 
to a hot standby. Depending on the environment (development or production) 
these are different machines. Here's a minimal working example of what I had in 
mind:
```py
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(value: str):
        print(value)

    task_print(values["{{ params.selector }}"])


playground()

if __name__ == "__main__":
    playground().test()
```
However, with this approach I get the following error during serialisation:
```
  File "/path/to/dag/dir/dag_playground.py", line 28, in playground
    task_print(values["{{ params.selector }}"])
               ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '{{ params.selector }}'
```
This indicates that the template isn't rendered during serialisation.  
Any ideas how to circumvent this issue?

GitHub link: https://github.com/apache/airflow/discussions/58275

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]

Reply via email to