Repository: apache/airflow
Pull request: [#16460]: Fixed typos in task regex param
Backfill should not create a DagRun in case there is no any task that matches the regex.

closes: #16460


Problem statement:
Typos in Backfill's `task-regex` param
Example:
DAG structure:
```
default_args = {
    'owner': 'dimon',
    'depends_on_past': False,
    'start_date': datetime(2021, 1, 10)
}

dag = DAG(
    'dummy-dag',
    schedule_interval='21 2 * * *',
    catchup=False,
    default_args=default_args
)

DagContext.push_context_managed_dag(dag)
task1 = BashOperator(task_id='task1', bash_command='echo 1')
task2 = BashOperator(task_id='task2', bash_command='echo 2')
task2 << task1
task3 = BashOperator(task_id='task3', bash_command='echo 3')
```

Let’s say you’ve missed the button and typed `--task-regex task4`.
When the backfill starts, firstly it will create a new empty DagRun and puts it in DB. Then the backfill job will go and try to find tasks that match the regex you’ve entered, will not find any obviously and will be stuck in the “running” state together with newly created DagRun forever.

Hints from issue discussion:

Commit message: [#16460]: Fixed pre-commit issue

Patch to review:
diff --git a/airflow/cli/commands/dag_command.py b/airflow/cli/commands/dag_command.py
index fe2f329fef5db..319652e634895 100644
--- a/airflow/cli/commands/dag_command.py
+++ b/airflow/cli/commands/dag_command.py
@@ -78,6 +78,10 @@ def dag_backfill(args, dag=None):
         dag = dag.partial_subset(
             task_ids_or_regex=args.task_regex, include_upstream=not args.ignore_dependencies
         )
+        if not dag.task_dict:
+            raise AirflowException(
+                f"There is no any task that match '{args.task_regex}' regex. Nothing to run, exiting..."
+            )
 
     run_conf = None
     if args.conf:


Code review comments:
diff_hunk: @@ -78,6 +78,10 @@ def dag_backfill(args, dag=None):
         dag = dag.partial_subset(
             task_ids_or_regex=args.task_regex, include_upstream=not args.ignore_dependencies
         )
+        if not dag.task_dict:
+            raise AirflowException(
+                f"There is no any task that match '{args.task_regex}' regex. Nothing to run, exiting..."
path: airflow/cli/commands/dag_command.py
text: @user1:
```suggestion
                f"There are no tasks that match '{args.task_regex}' regex. Nothing to run, exiting..."
```