Skip to content

Commit

Permalink
Revert "Make current working directory as templated field in BashOper…
Browse files Browse the repository at this point in the history
…ator (apache#37928)" (apache#37952)

This reverts commit db07eb1.
  • Loading branch information
potiuk authored and howardyoo committed Mar 31, 2024
1 parent 8c18c88 commit b05ff21
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
6 changes: 2 additions & 4 deletions airflow/operators/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ class BashOperator(BaseOperator):
:param skip_on_exit_code: If task exits with this exit code, leave the task
in ``skipped`` state (default: 99). If set to ``None``, any non-zero
exit code will be treated as a failure.
:param cwd: Working directory to execute the command in (templated).
:param cwd: Working directory to execute the command in.
If None (default), the command is run in a temporary directory.
To use current DAG folder as the working directory,
you might set template ``{{ dag_run.dag.folder }}``.
Airflow will evaluate the exit code of the Bash command. In general, a non-zero exit code will result in
task failure and zero will result in task success.
Expand Down Expand Up @@ -132,7 +130,7 @@ class BashOperator(BaseOperator):
"""

template_fields: Sequence[str] = ("bash_command", "env", "cwd")
template_fields: Sequence[str] = ("bash_command", "env")
template_fields_renderers = {"bash_command": "bash", "env": "json"}
template_ext: Sequence[str] = (".sh", ".bash")
ui_color = "#f0ede4"
Expand Down
20 changes: 0 additions & 20 deletions tests/operators/test_bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import os
import signal
from datetime import datetime, timedelta
from pathlib import Path
from time import sleep
from unittest import mock

Expand Down Expand Up @@ -245,22 +244,3 @@ def test_bash_operator_kill(self, dag_maker):
os.kill(proc.pid, signal.SIGTERM)
assert False, "BashOperator's subprocess still running after stopping on timeout!"
break

@pytest.mark.db_test
def test_templated_fields(self, create_task_instance_of_operator):
ti = create_task_instance_of_operator(
BashOperator,
# Templated fields
bash_command='echo "{{ dag_run.dag_id }}"',
env={"FOO": "{{ ds }}"},
cwd="{{ dag_run.dag.folder }}",
# Other parameters
dag_id="test_templated_fields_dag",
task_id="test_templated_fields_task",
execution_date=timezone.datetime(2024, 2, 1, tzinfo=timezone.utc),
)
ti.render_templates()
task: BashOperator = ti.task
assert task.bash_command == 'echo "test_templated_fields_dag"'
assert task.env == {"FOO": "2024-02-01"}
assert task.cwd == Path(__file__).absolute().parent.as_posix()

0 comments on commit b05ff21

Please sign in to comment.