This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 35fef2befb Revert "Make current working directory as templated field
in BashOperator (#37928)" (#37952)
35fef2befb is described below
commit 35fef2befb1e95ffecd0d1c254544e69268d91b7
Author: Jarek Potiuk <[email protected]>
AuthorDate: Wed Mar 6 22:00:49 2024 +0100
Revert "Make current working directory as templated field in BashOperator
(#37928)" (#37952)
This reverts commit db07eb1957a729f333c14ce3c26b5a819736295b.
---
airflow/operators/bash.py | 6 ++----
tests/operators/test_bash.py | 20 --------------------
2 files changed, 2 insertions(+), 24 deletions(-)
diff --git a/airflow/operators/bash.py b/airflow/operators/bash.py
index f1edb0d46d..ff8edcba51 100644
--- a/airflow/operators/bash.py
+++ b/airflow/operators/bash.py
@@ -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.
@@ -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"
diff --git a/tests/operators/test_bash.py b/tests/operators/test_bash.py
index 7a52790bcb..d00477b118 100644
--- a/tests/operators/test_bash.py
+++ b/tests/operators/test_bash.py
@@ -20,7 +20,6 @@ from __future__ import annotations
import os
import signal
from datetime import datetime, timedelta
-from pathlib import Path
from time import sleep
from unittest import mock
@@ -245,22 +244,3 @@ class TestBashOperator:
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()