diff --git a/airflow/cli/cli_config.py b/airflow/cli/cli_config.py index abefb5cd631b..799b8ed92721 100644 --- a/airflow/cli/cli_config.py +++ b/airflow/cli/cli_config.py @@ -432,7 +432,11 @@ def string_lower_type(val): ) # list_tasks -ARG_TREE = Arg(("-t", "--tree"), help="Tree view", action="store_true") +ARG_TREE = Arg( + ("-t", "--tree"), + help="Deprecated - use `dags show` instead. Display tasks in a tree. Note that generating the tree can be slow and the output very large for some DAGs.", + action="store_true", +) # tasks_run # This is a hidden option -- not meant for users to set or know about diff --git a/airflow/models/dag.py b/airflow/models/dag.py index ace9650f50f2..f84834678085 100644 --- a/airflow/models/dag.py +++ b/airflow/models/dag.py @@ -2772,6 +2772,12 @@ def pickle(self, session=NEW_SESSION) -> DagPickle: def tree_view(self) -> None: """Print an ASCII tree representation of the DAG.""" + warnings.warn( + "`tree_view` is deprecated and will be removed in Airflow 3.0.", + category=RemovedInAirflow3Warning, + stacklevel=2, + ) + for tmp in self._generate_tree_view(): print(tmp) @@ -2787,6 +2793,12 @@ def get_downstream(task, level=0) -> Generator[str, None, None]: def get_tree_view(self) -> str: """Return an ASCII tree representation of the DAG.""" + warnings.warn( + "`get_tree_view` is deprecated and will be removed in Airflow 3.0.", + category=RemovedInAirflow3Warning, + stacklevel=2, + ) + rst = "" for tmp in self._generate_tree_view(): rst += tmp + "\n" diff --git a/tests/models/test_dag.py b/tests/models/test_dag.py index 6e7d2d3894a2..f23eac76b6e9 100644 --- a/tests/models/test_dag.py +++ b/tests/models/test_dag.py @@ -1653,7 +1653,11 @@ def test_tree_view(self): op1_a >> op2 >> op3 with redirect_stdout(StringIO()) as stdout: - dag.tree_view() + with pytest.warns( + RemovedInAirflow3Warning, + match="`tree_view` is deprecated and will be removed in Airflow 3.0", + ): + dag.tree_view() stdout = stdout.getvalue() stdout_lines = stdout.splitlines() @@ -1661,7 +1665,13 @@ def test_tree_view(self): assert "t2" in stdout_lines[1] assert "t3" in stdout_lines[2] assert "t1_b" in stdout_lines[3] - assert dag.get_tree_view() == ( + + with pytest.warns( + RemovedInAirflow3Warning, + match="`get_tree_view` is deprecated and will be removed in Airflow 3.0", + ): + get_tree_view = dag.get_tree_view() + assert get_tree_view == ( "\n" " \n" " \n"