itzzdev09 commented on code in PR #72163:
URL: https://github.com/apache/airflow/pull/72163#discussion_r3876090824


##########
airflow-ctl/src/airflowctl/ctl/commands/task_command.py:
##########
@@ -126,6 +126,37 @@ def failed_deps(args, api_client=NEW_API_CLIENT) -> None:
         )
 
 
+@provide_api_client(kind=ClientKind.CLI)
+def state(args, api_client=NEW_API_CLIENT) -> None:
+    """Get the state of a task instance."""
+    if (args.run_id is None) == (args.logical_date is None):
+        rich.print("[red]Provide either run_id or --logical-date, but not 
both[/red]")
+        sys.exit(1)
+
+    run_id = args.run_id or _find_run_id_by_logical_date(api_client, 
args.dag_id, args.logical_date)

Review Comment:
   Made it explicit in 2e1d575 — thanks.
   
   I kept the check covering both cases rather than only "both given", because 
the snippet above changes behaviour when *neither* is passed: `run_id` stays 
`None` and we fall through to `_find_run_id_by_logical_date(..., None)`, which 
raises `AttributeError` on `None.replace(...)` instead of printing the error 
and exiting 1. `test_state_requires_exactly_one_of_run_id_and_logical_date` 
covers both inputs (`ids=["neither", "both"]`), so that path is asserted.
   
   What it looks like now:
   
   ```python
   has_run_id = args.run_id is not None
   has_logical_date = args.logical_date is not None
   # Rejects both "neither given" and "both given".
   if has_run_id == has_logical_date:
       rich.print("[red]Provide either run_id or --logical-date, but not 
both[/red]")
       sys.exit(1)
   
   if has_run_id:
       run_id = args.run_id
   else:
       run_id = _find_run_id_by_logical_date(api_client, args.dag_id, 
args.logical_date)
   ```
   
   One note: `failed_deps` and `states_for_dag_run` still use the compact 
`(args.run_id is None) == (args.logical_date is None)` form — I'd originally 
matched them for consistency. Happy to convert those two in this PR as well if 
you'd prefer all three to read the same way; I left them alone to keep the diff 
to the new command.



-- 
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