Repository navigation
Show a clean error when airflow backfill create targets an unknown Dag - #72893
Eason09053360 wants to merge 1 commit into
Conversation
The command let DagNotFound escape from the model layer, so a mistyped --dag-id produced a full traceback rather than a one-line message. In the --dry-run path the exception surfaced even later, because _do_dry_run is a generator whose body only runs on iteration, after the session block had already exited. Catching it at the CLI boundary and consuming the generator inside that block reports the missing Dag the same way the other CLI "not found" paths do, with the exit code unchanged.
|
Hello @Eason09053360 - thank you for your contributions to Apache Airflow! The Airflow community has introduced a limit of 5 open pull requests at a time for contributors without write access to the repository. You currently have 33 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:
These pull requests stay open because maintainers are already engaged in them - they count towards your limit:
This is not a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are. What we ask you to do is to make your first prioritization decision: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack. Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst. Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting |
airflow backfill create --dag-id <unknown>now prints a one-line error and exits 1 instead of dumping aDagNotFoundtraceback, in both the normal and--dry-runpaths.Why
Mistyping the Dag id is the most ordinary user error this command can see, and today it looks like a crash:
The model layer raises
DagNotFoundon purpose (it serves both the REST API and the CLI), and the REST route already maps it to a 404. The CLI handler only caughtNoBackfillRunsToCreate, so this exception escaped untranslated. Every other CLI "Dag does not exist" path (dags list-jobs,dags list-runs,dags state, ...) already reports it as a plain message on stderr.The
--dry-runpath had a second wrinkle:_do_dry_runis a generator, so its body (including the Dag lookup that raises) only ran when the result was iterated, which happened after thecreate_session()block had exited and outside anytry.What
DagNotFoundat the CLI boundary and re-raise it asSystemExit(str(e)), which writes the message to stderr and exits 1, the same idiom the other CLI "not found" paths use. The exit code is unchanged from the traceback case, so scripts checking$?see no difference._do_dry_run(...)withlist(...)inside the session block and thetry. Without this the new handler would be unreachable, because the exception surfaces on iteration, not on the call. As a side effect the generator now runs while the session it was given is still open; previously it ran aftersession.close().Deliberately out of scope: the sibling validation errors from the same two model calls (
AlreadyRunningBackfill,DagNonPeriodicScheduleException,DagRunTypeNotAllowed,InvalidBackfillDateRange, ...) still surface as tracebacks. They share the root cause but each needs its own message and test; this PR only fixes the missing-Dag case. Happy to follow up with the rest if reviewers prefer one PR.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Fable 5.1) following the guidelines