Is @DAG/@task decorators compatible with dynamically generation? #21278
-
Apache Airflow version2.2.3 (latest released) What happened
Running the DAG above, i retrieve the logs:
What you expected to happenThe variable takes the same value during DAG generation and methods execution:
How to reproduceRun the DAG above Operating SystemmacOS Monterey 12.1 Versions of Apache Airflow ProvidersNo response DeploymentDocker-Compose Deployment detailsNo response Anything elseNo response Are you willing to submit PR?
Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Thanks for opening your first issue here! Be sure to follow the issue template! |
Beta Was this translation helpful? Give feedback.
-
This is not an issue - this is a discussion. I believe it is pretty expectedw way how decorators work, but I wonder what others have to say on thtat one. |
Beta Was this translation helpful? Give feedback.
-
This isn't anything to do with the TaskFlow directly, it's how python scoping works with for-loops, coupled with now DAGs are parsed.
So when the task function is executed, the current/latest value of The way to do this and get the behaviour you want is to use
|
Beta Was this translation helpful? Give feedback.
This isn't anything to do with the TaskFlow directly, it's how python scoping works with for-loops, coupled with now DAGs are parsed.
test_task(dag_id)
will be called with 1..3 as the valuesdag_id
variable is left attest_dag_3
So when the task function is executed, the current/latest value of
dag_id
variable is the one you get.The way to do this and get the behaviour you want is to use
dag
from the context: