Skip to content

Share airflowctl's Dag run lookup without a new request for run_id - #70904

Open
rjgoyln wants to merge 1 commit into
apache:mainfrom
rjgoyln:refactor/airflowctl-dag-run-lookup
Open

Share airflowctl's Dag run lookup without a new request for run_id#70904
rjgoyln wants to merge 1 commit into
apache:mainfrom
rjgoyln:refactor/airflowctl-dag-run-lookup

Conversation

@rjgoyln

@rjgoylnrjgoyln commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

airflowctl tasks failed-deps and airflowctl tasks states-for-dag-run intentionally do not look up a Dag run when the user supplies a run_id; the ID is passed directly to the task-instance endpoint. That behavior was introduced in #69915 to avoid an unnecessary HTTP request, but the remaining logical-date lookup and selector validation were duplicated across commands.

This PR moves the shared logic into airflowctl/ctl/utils/dag_run.py, removing the duplication while preserving the existing request pattern and user-visible behavior.

Why two resolvers?

The split is intentional.

  • resolve_dag_run_id returns a supplied run_id directly, avoiding the extra Dag run lookup.
  • resolve_dag_run fetches the Dag run because commands such as dags state need the full response to display fields such as state and conf.

Both helpers share the selector validation and logical-date lookup, but keep the different run_id behavior intact.

A single parameterized resolver was considered, but since the two helpers naturally return different types (str vs DAGRunResponse), combining them would require either a union return type or @overload definitions. That adds more complexity than the small amount of dispatch logic it would eliminate.

Tests

The "don't look up a supplied run_id" behavior was previously not enforced by the test suite.

As a demonstration, adding a verification-only dag_runs.get call (for example, to validate a supplied run_id) produces the following result:

BranchResult
main30/30 tests pass
This branchExactly 2 tests fail (the assertions added here)

The new assertions make this behavior an explicit contract and prevent future refactors from unintentionally adding the extra request.

Notes

  • No behavior change is intended. Request counts, error messages, and exit paths remain unchanged.
  • No newsfragment: airflow-ctl release managers regenerate the changelog from git log.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5)

Generated-by: Claude Code (Opus 5) following the guidelines

The dags and tasks commands each carried their own copy of the same
logical-date Dag run lookup, differing only in what they returned, and each
repeated the run-selector guard in front of it. Sharing them lets the selector
handling live in one place rather than in front of every command that accepts
one.
A supplied run_id is deliberately still taken at face value rather than
fetched, so commands acting on a nested resource keep reporting a miss against
that resource instead of against the Dag run. The added assertions pin that
down, since collapsing the two resolvers would otherwise silently add a
request and re-attribute the 404.
@rjgoylnrjgoyln changed the title Deduplicate the Dag run lookup in airflowctl dag and task commandsShare airflowctl's Dag run lookup without a new request for run_idAug 1, 2026
@rjgoyln
rjgoyln marked this pull request as ready for review August 1, 2026 15:07

@SameerMesiah97SameerMesiah97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. This is a relatively low-risk refactor,

@potiukpotiuk added the ready for maintainer review Set after triaging when all criteria pass. label Aug 13, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@rjgoyln@SameerMesiah97@potiuk