Skip executor validation when a worker parses a Dag by namanjain24-sudo · Pull Request #73172 · apache/airflow · GitHub
Skip to content

Skip executor validation when a worker parses a Dag - #73172

Draft
namanjain24-sudo wants to merge 1 commit into
apache:mainfrom
namanjain24-sudo:fix-executor-validation-in-worker
Draft

namanjain24-sudo wants to merge 1 commit into
apache:mainfrom
namanjain24-sudo:fix-executor-validation-in-worker

Conversation

@namanjain24-sudo

Copy link
Copy Markdown
Contributor

A task with executor="KubernetesExecutor" fails to start when the worker it lands on has a different executor configured, with the error from #56271:

UnknownExecutorException: Task 'a' specifies executor 'KubernetesExecutor', which is not available ...

parse() in the task runner loads the Dag through BundleDagBag, and DagBag.process_file runs _validate_executor_fields on every Dag it bags. A worker usually has only its own executor configured. The cncf-kubernetes pod templates, for example kubernetes_executor_templates/basic_template.yaml and the files in pod_template_file_examples/, set AIRFLOW__CORE__EXECUTOR=LocalExecutor. So the check fails inside the pod, the Dag is dropped from the bag, and the task cannot start.

The Dag processor has already run this check when it parsed the file, so the worker does not need to repeat it. This adds a validate_executors argument to DagBag that defaults to True, and the task runner passes False. The Dag processor, the CLI and dag.test() keep validating as before.

Tests:

  • test_parse_does_not_validate_task_executors parses a Dag whose task uses an executor the worker does not know. It fails on main with the error above and passes with this change.
  • test_validate_executors in test_dagbag.py covers both values of the new argument.
  • test_task_runner.py (536 passed with TZ=UTC; in a non-UTC local timezone eight TestTriggerDagRunOperator tests fail on main as well), test_dagbag.py (76 passed, 1 skipped) and prek, including mypy for airflow-core and task-sdk, pass locally.

closes: #56271


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: a Gen-AI coding assistant, following the guidelines. I reviewed the change and ran the checks above.

A worker loads the Dag through BundleDagBag, which validated every task's
executor against the worker's own [core] executor setting. Worker pods
usually have only their own executor configured (the cncf-kubernetes pod
templates set LocalExecutor), so a task with executor="KubernetesExecutor"
was dropped and could not start.

The Dag processor already validates executors, so add a validate_executors
argument to DagBag and turn it off in the task runner.
Sign up for free to 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.

KubernetesExecutor feature may be broken in 3.1.0

1 participant