Skip to content

Commit

Permalink
Update the "legacy command" help text for backfill (apache#43764)
Browse files Browse the repository at this point in the history
In 1.x there was an `airflow backfill` command.  In 2.x it became `airflow dags backfill`.

In 3.x it's back to `airflow backfill`.

Need to update the "yo, your command been moved" text.
  • Loading branch information
dstandish authored Nov 12, 2024
1 parent f924ecb commit edb3fe0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
11 changes: 9 additions & 2 deletions airflow/cli/commands/legacy_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"show_dag": "dags show",
"list_dag": "dags list",
"dag_status": "dags status",
"backfill": "dags backfill",
"list_dag_runs": "dags list-runs",
"pause": "dags pause",
"unpause": "dags unpause",
Expand All @@ -46,12 +45,20 @@
"list_users": "users list",
"create_user": "users create",
"delete_user": "users delete",
"dags backfill": "backfill create",
}


def check_legacy_command(action, value):
"""Check command value and raise error if value is in removed command."""
new_command = COMMAND_MAP.get(value)
if not hasattr(action, "_prog_prefix"):
return
prefix = action._prog_prefix.replace("airflow ", "")

full_command = f"{prefix} {value}"
if not new_command:
new_command = COMMAND_MAP.get(full_command)
if new_command is not None:
msg = f"`airflow {value}` command, has been removed, please use `airflow {new_command}`"
msg = f"Command `{full_command}` has been removed. Please use `airflow {new_command}`"
raise ArgumentError(action, msg)
21 changes: 11 additions & 10 deletions tests/cli/commands/test_legacy_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"show_dag",
"list_dag",
"dag_status",
"backfill",
"dags backfill",
"list_dag_runs",
"pause",
"unpause",
Expand Down Expand Up @@ -69,19 +69,20 @@ def test_should_display_value(self):

assert 2 == ctx.value.code
assert (
"`airflow worker` command, has been removed, "
"please use `airflow celery worker`, see help above." in temp_stderr.getvalue().strip()
"Command `airflow worker` has been removed. "
"Please use `airflow celery worker`" in temp_stderr.getvalue().strip()
)

def test_command_map(self):
for item in LEGACY_COMMANDS:
assert COMMAND_MAP[item] is not None

def test_check_legacy_command(self):
action = MagicMock()
with pytest.raises(ArgumentError) as ctx:
check_legacy_command(action, "list_users")
assert (
str(ctx.value)
== "argument : `airflow list_users` command, has been removed, please use `airflow users list`"
)
mock_action = MagicMock()
mock_action._prog_prefix = "airflow"
with pytest.raises(
ArgumentError,
match="argument : Command `airflow list_users` has been removed. "
"Please use `airflow users list`",
):
check_legacy_command(mock_action, "list_users")

0 comments on commit edb3fe0

Please sign in to comment.