This is an automated email from the ASF dual-hosted git repository. jedcunningham pushed a commit to branch v2-2-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit d9af96539694dc85c85a86fc0acf7fea00569b13 Author: Sam Wheating <[email protected]> AuthorDate: Fri Oct 15 00:38:23 2021 -0700 CLI: Fail ``backfill`` command before loading DAGs if missing args (#18994) I was looking through some of the CLI code last week trying to improve the speed of `airflow user` commands and I noticed this small issue. If neither the `start_date` or `end_date` argument is provided then the command will fail, but it will first parse all of the DAGs which can take up to several minutes in large deployments. Now the command will fail faster, allowing the user to adjust their command and retry. (cherry picked from commit b814ab43d62fad83c1083a7bc3a8d009c6103213) --- airflow/cli/commands/dag_command.py | 4 ++-- tests/cli/commands/test_dag_command.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/airflow/cli/commands/dag_command.py b/airflow/cli/commands/dag_command.py index 30b0148..b94d6cf 100644 --- a/airflow/cli/commands/dag_command.py +++ b/airflow/cli/commands/dag_command.py @@ -67,11 +67,11 @@ def dag_backfill(args, dag=None): if args.ignore_first_depends_on_past is False: args.ignore_first_depends_on_past = True - dag = dag or get_dag(args.subdir, args.dag_id) - if not args.start_date and not args.end_date: raise AirflowException("Provide a start_date and/or end_date") + dag = dag or get_dag(args.subdir, args.dag_id) + # If only one date is passed, using same as start and end args.end_date = args.end_date or args.start_date args.start_date = args.start_date or args.end_date diff --git a/tests/cli/commands/test_dag_command.py b/tests/cli/commands/test_dag_command.py index 67dcabe..0044761 100644 --- a/tests/cli/commands/test_dag_command.py +++ b/tests/cli/commands/test_dag_command.py @@ -158,6 +158,16 @@ class TestCliDags(unittest.TestCase): ) mock_run.reset_mock() + @mock.patch("airflow.cli.commands.dag_command.get_dag") + def test_backfill_fails_without_loading_dags(self, mock_get_dag): + + cli_args = self.parser.parse_args(['dags', 'backfill', 'example_bash_operator']) + + with pytest.raises(AirflowException): + dag_command.dag_backfill(cli_args) + + mock_get_dag.assert_not_called() + def test_show_dag_print(self): with contextlib.redirect_stdout(io.StringIO()) as temp_stdout: dag_command.dag_show(self.parser.parse_args(['dags', 'show', 'example_bash_operator']))
