Replies: 3 comments 3 replies
-
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval. |
Beta Was this translation helpful? Give feedback.
-
Thank you for trying to improve the docs!
But it's OK to use Could you check https://stackoverflow.com/a/71758614/14624409 if that clarify the issue we can work on modifying the docs to reflect it. |
Beta Was this translation helpful? Give feedback.
-
Hi @eladkal! thanks for your information. bash_use_variable_bad_2 = BashOperator(
task_id="bash_use_variable_bad_2",
bash_command=f"echo variable foo=${Variable.get('foo')}", # DON'T DO THAT
)
bash_use_variable_bad_3 = BashOperator(
task_id="bash_use_variable_bad_3",
bash_command="echo variable foo=${foo_env}",
env={"foo_env": Variable.get("foo")}, # DON'T DO THAT
) |
Beta Was this translation helpful? Give feedback.
-
What do you see as an issue?
In the Airflow Best Practices article, I found a paragraph that was confusing to readers:
Bad example:
Good example:
In the "Bad Example" section, it states that
Variable.get("foo")
should not be specified in an Operator. Instead, it recommends calling it using a Jinja template, as described in the "Good Example" section.However, it explains that it is possible to call it in the
@task
operator. This might make it seem like users who want to call theVariable.get()
method shouldn't do so in a traditional Operator.Secondly, to simplify the code, the Operators are not in the DAG and are not indented, so there is room for interpretation that the
BashOperators
in the bad example are outside the DAG (top-level code), and therefore theVariable.get()
method is also top-level.Solving the problem
I think some sentences should be added to explain why
Variable.get()
methods called from inside an Operator are a bad example.I don't know enough about the logic that the scheduler is parsing to make a precise suggestion, but I think there are cases like this
Variable.get()
method inside an Operator, and using a Jinja template is absolutely fine: add to the documentation why callingVariable.get()
inside an Operator is recognized as top-level code, and callingVariable.get()
inside a@task
operator is fine.Variable.get()
method inside an Operator: add appropriate examples to the documentationAnything else
No response
Are you willing to submit PR?
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions