henry3260 commented on code in PR #72941:
URL: https://github.com/apache/airflow/pull/72941#discussion_r4335176015


##########
airflow-core/src/airflow/cli/commands/task_command.py:
##########
@@ -600,9 +601,13 @@ def task_clear(args) -> None:
         dags = get_dags(args.bundle_name, args.dag_id, 
use_regex=args.dag_regex, from_db=True)
 
         if args.task_regex:
+            try:

Review Comment:
   The compile runs after get_dags(), so a bad dag_id masks a bad pattern, and 
under -R you pay a full DagBag parse before the error. Hoisting the if 
args.task_regex: compile block above the if args.dag_id and not ... branch 
validates command-line input before any DB access.



##########
airflow-core/src/airflow/cli/commands/task_command.py:
##########
@@ -600,9 +601,13 @@ def task_clear(args) -> None:
         dags = get_dags(args.bundle_name, args.dag_id, 
use_regex=args.dag_regex, from_db=True)
 
         if args.task_regex:
+            try:
+                task_pattern = re.compile(args.task_regex)
+            except re.error as e:
+                raise SystemExit(f"Invalid --task-regex {args.task_regex!r}: 
{e}")
             for idx, dag in enumerate(dags):
                 dags[idx] = dag.partial_subset(
-                    task_ids=args.task_regex,
+                    task_ids={task_id for task_id in dag.task_ids if 
task_pattern.search(task_id)},

Review Comment:
   A valid-but-mistyped pattern still exits 0 with no output. An empty set 
gives a partial dag whose clear() filters on TaskInstance.task_id.in_([]) — 
zero rows, no message — so "cleared nothing" looks identical to "cleared 
successfully".
   
   That's half of the asymmetry this PR closes: --dag-regex raises when nothing 
matches (airflow/utils/cli.py:694), --task-regex still doesn't.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to