Replies: 1 comment 1 reply
-
|
Your code works, but it’s a hack. Prefer setting env directly in the operator or using templating. Keep callbacks for side effects, not for parameter wiring. In your case, I recommend pulling the connection inside the bash_command or setting it at the DAG parse time.
from airflow.hooks.base import BaseHook
vc = BaseHook.get_connection("my_connection")
bash = BashOperator(
task_id="also_run_this",
bash_command=f'echo {vc.host}'
)
from airflow.hooks.base import BaseHook
vc = BaseHook.get_connection("my_connection")
bash = BashOperator(
task_id="also_run_this",
bash_command="echo $varenv",
env={"varenv": vc.host},
) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I wonder if I might have a problem with this type of use of on_execute_callback, as far as I've tested I suppose that's ok but I may miss something important :
Beta Was this translation helpful? Give feedback.
All reactions