hkc-8010 commented on issue #33600:
URL: https://github.com/apache/airflow/issues/33600#issuecomment-1971838010
Hey @agomez-etsy ,
How about defining custom_args as dag_level params in default_args and then
use it in creating Dynamic tasks?
Below is an example. I tested this on my local and its working.
```
from airflow.decorators import dag, task
from datetime import datetime
from airflow.operators.python import get_current_context
import logging
DEFAULT_TASK_ARGS = {
"owner": "myteam",
"params": {
"project_id": "myproject",
"custom_arg": "foo",
}
}
@task
def foo() -> list[str]:
return ["a", "b", "c"]
@task
def bar(val):
context = get_current_context()
project_id = context['params']['project_id']
custom_arg = context['params']['custom_arg']
logging.info(val)
logging.info(project_id)
logging.info(custom_arg)
@dag(default_args=DEFAULT_TASK_ARGS, schedule_interval=None,
start_date=datetime(2021, 1, 1), catchup=False, dag_id='params_example')
def params_example():
dynamic_tasks = bar.expand(val=foo())
dynamic_tasks
params_example_dag = params_example()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]