Skip to content

Commit

Permalink
backfill job command cli deperecated options removed (#41739)
Browse files Browse the repository at this point in the history
* backfill job command cli deperecated options removed

* news fragment added
  • Loading branch information
dirrao authored Aug 27, 2024
1 parent 83ba17f commit 7caf268
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 62 deletions.
16 changes: 0 additions & 16 deletions airflow/cli/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,6 @@ def string_lower_type(val):
),
action="store_true",
)
ARG_BF_IGNORE_FIRST_DEPENDS_ON_PAST = Arg(
("-I", "--ignore-first-depends-on-past"),
help=(
"Ignores depends_on_past dependencies for the first "
"set of tasks only (subsequent executions in the backfill "
"DO respect depends_on_past)"
),
action="store_true",
)
ARG_POOL = Arg(("--pool",), "Resource pool to use")
ARG_DELAY_ON_LIMIT = Arg(
("--delay-on-limit",),
Expand Down Expand Up @@ -383,11 +374,6 @@ def string_lower_type(val):
action="store_true",
)

ARG_TREAT_DAG_AS_REGEX = Arg(
("--treat-dag-as-regex",),
help=("Deprecated -- use `--treat-dag-id-as-regex` instead"),
action="store_true",
)

ARG_TREAT_DAG_ID_AS_REGEX = Arg(
("--treat-dag-id-as-regex",),
Expand Down Expand Up @@ -1230,7 +1216,6 @@ class GroupCommand(NamedTuple):
ARG_CONTINUE_ON_FAILURES,
ARG_DISABLE_RETRY,
ARG_BF_IGNORE_DEPENDENCIES,
ARG_BF_IGNORE_FIRST_DEPENDS_ON_PAST,
ARG_SUBDIR,
ARG_POOL,
ARG_DELAY_ON_LIMIT,
Expand All @@ -1240,7 +1225,6 @@ class GroupCommand(NamedTuple):
ARG_RESET_DAG_RUN,
ARG_RERUN_FAILED_TASKS,
ARG_RUN_BACKWARDS,
ARG_TREAT_DAG_AS_REGEX,
ARG_TREAT_DAG_ID_AS_REGEX,
),
),
Expand Down
17 changes: 1 addition & 16 deletions airflow/cli/commands/dag_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import signal
import subprocess
import sys
import warnings
from typing import TYPE_CHECKING

import re2
Expand All @@ -37,7 +36,7 @@
from airflow.api_connexion.schemas.dag_schema import dag_schema
from airflow.cli.simple_table import AirflowConsole
from airflow.configuration import conf
from airflow.exceptions import AirflowException, RemovedInAirflow3Warning
from airflow.exceptions import AirflowException
from airflow.jobs.job import Job
from airflow.models import DagBag, DagModel, DagRun, TaskInstance
from airflow.models.dag import DAG
Expand Down Expand Up @@ -133,22 +132,8 @@ def dag_backfill(args, dag: list[DAG] | DAG | None = None) -> None:
"""Create backfill job or dry run for a DAG or list of DAGs using regex."""
logging.basicConfig(level=settings.LOGGING_LEVEL, format=settings.SIMPLE_LOG_FORMAT)
signal.signal(signal.SIGTERM, sigint_handler)
if args.ignore_first_depends_on_past:
warnings.warn(
"--ignore-first-depends-on-past is deprecated as the value is always set to True",
category=RemovedInAirflow3Warning,
stacklevel=4,
)
args.ignore_first_depends_on_past = True

if not args.treat_dag_id_as_regex and args.treat_dag_as_regex:
warnings.warn(
"--treat-dag-as-regex is deprecated, use --treat-dag-id-as-regex instead",
category=RemovedInAirflow3Warning,
stacklevel=4,
)
args.treat_dag_id_as_regex = args.treat_dag_as_regex

if not args.start_date and not args.end_date:
raise AirflowException("Provide a start_date and/or end_date")

Expand Down
3 changes: 3 additions & 0 deletions newsfragments/41739.significant.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Removed backfill job command cli option ``ignore-first-depends-on-past``. Its value always set to True. No replcaement cli option.

Removed backfill job command cli option ``treat-dag-as-regex``. Please use ``treat-dag-id-as-regex`` instead.
33 changes: 3 additions & 30 deletions tests/cli/commands/test_dag_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from airflow.cli import cli_parser
from airflow.cli.commands import dag_command
from airflow.decorators import task
from airflow.exceptions import AirflowException, RemovedInAirflow3Warning
from airflow.exceptions import AirflowException
from airflow.models import DagBag, DagModel, DagRun
from airflow.models.baseoperator import BaseOperator
from airflow.models.dag import _run_inline_trigger
Expand Down Expand Up @@ -247,24 +247,6 @@ def test_backfill(self, mock_run):
assert f"Dry run of DAG example_branch_operator on {DEFAULT_DATE_REPR}\n" in output
assert "Task run_this_first located in DAG example_branch_operator\n" in output

@mock.patch("airflow.cli.commands.dag_command._run_dag_backfill")
def test_backfill_treat_dag_as_regex_deprecation(self, _):
run_date = DEFAULT_DATE + timedelta(days=1)
cli_args = self.parser.parse_args(
[
"dags",
"backfill",
"example_bash_operator",
"--treat-dag-as-regex",
"--start-date",
run_date.isoformat(),
]
)

with pytest.warns(DeprecationWarning, match="--treat-dag-as-regex is deprecated"):
dag_command.dag_backfill(cli_args)
assert cli_args.treat_dag_id_as_regex == cli_args.treat_dag_as_regex

@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"])
Expand Down Expand Up @@ -331,15 +313,8 @@ def test_show_dag_imgcat(self, mock_render_dag, mock_popen):
assert "OUT" in out
assert "ERR" in out

@pytest.mark.parametrize(
"cli_arg",
[
pytest.param("-I", id="short"),
pytest.param("--ignore-first-depends-on-past", id="full"),
],
)
@mock.patch("airflow.cli.commands.dag_command.DAG.run")
def test_cli_backfill_deprecated_ignore_first_depends_on_past(self, mock_run, cli_arg: str):
def test_cli_backfill_ignore_first_depends_on_past(self, mock_run):
"""
Test that CLI respects -I argument
Expand All @@ -355,12 +330,10 @@ def test_cli_backfill_deprecated_ignore_first_depends_on_past(self, mock_run, cl
"--local",
"--start-date",
run_date.isoformat(),
cli_arg,
]
dag = self.dagbag.get_dag(dag_id)

with pytest.warns(RemovedInAirflow3Warning, match="ignore-first-depends-on-past is deprecated"):
dag_command.dag_backfill(self.parser.parse_args(args), dag=dag)
dag_command.dag_backfill(self.parser.parse_args(args), dag=dag)

mock_run.assert_called_once_with(
start_date=run_date,
Expand Down

0 comments on commit 7caf268

Please sign in to comment.