itzzdev09 commented on code in PR #72163:
URL: https://github.com/apache/airflow/pull/72163#discussion_r3876092295
##########
airflow-ctl/src/airflowctl/ctl/cli_config.py:
##########
@@ -1199,6 +1199,22 @@ def merge_commands(
ARG_MAP_INDEX,
),
),
+ ActionCommand(
+ name="state",
+ help="Get the state of a task instance",
+ description=(
+ "Get the state of a task instance. "
+ "Select the run with either run_id or --logical-date (pass exactly
one)."
Review Comment:
Good question — I dug into it, and multiple matches aren't possible.
`DagRun` declares a uniqueness constraint on the pair:
```python
UniqueConstraint("dag_id", "logical_date",
name="dag_run_dag_id_logical_date_key")
```
(`airflow-core/src/airflow/models/dagrun.py`)
The lookup filters `logical_date_gte == logical_date_lte == <value>`, i.e.
an exact match on that column, so within one `dag_id` the query can return at
most one row. `order_by="-id"` therefore doesn't disambiguate anything, and
`limit=1` is only a cheap guard rather than a tie-break.
I've left the query itself alone here: `_find_run_id_by_logical_date` is
pre-existing and shared with `tasks failed-deps` and `tasks
states-for-dag-run`, so dropping the ordering would change those two commands
as well — that felt out of scope for a PR adding a new command. Happy to do it
as a follow-up (or here, if you'd rather).
What I did change is the help text, so it states the selection rule instead
of leaving it implicit (2e1d575):
> Get the state of a task instance. Select the run with either run_id or
--logical-date (pass exactly one). --logical-date matches the Dag run with
exactly that logical date.
I described it as an exact match rather than "the latest matching run",
since given the constraint there's only ever one.
--
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]