Skip to content

Conversation

@akkik04
Copy link
Contributor

@akkik04 akkik04 commented Dec 11, 2025


Closes #56459

Problem

@task.kubernetes_cmd breaks when used with TaskFlow-style mapping inside a TaskGroup.
The root cause is that we didn't mark TaskFlow arguments (op_args / op_kwargs) as template_fields, thus the validation of the return value of the Python callable occurs before those fields are resolved by the TaskFlow/mapping machinery.

As a result, when group_task.expand(...) is used, the name parameter that reaches the task (echo_cmd is the task being used in the repro linked within the issue) is still a MappedArgument object, and the type check inside _generate_cmds sees a non-str element and raises the TypeError: Expected echo_cmd to return a list of strings, but got ['echo', MappedArgument(...)].

Solution

I aligned @task.kubernetes_cmd with @task.kubernetes with regards to how templated fields are handled, so TaskFlow mappings behave consistently. Concretely, I extended template_fields to include op_args and op_kwargs alongside the existing Kubernetes-specific fields inherited from KubernetesPodOperator.template_fields. This ensures that TaskFlow arguments—including mapping metadata such as MappedArgument coming from TaskGroup.expand(...) will be run through the normal TaskFlow resolution scheme and reach the user function as plain Python values instead of unresolved mapping objects.

Finally, I add a focused unit test, test_kubernetes_cmd_template_fields_include_taskflow_args, which creates a simple @task.kubernetes_cmd TaskFlow function inside self.dag_maker, instantiates it, and asserts that the underlying operator’s template_fields include at least "op_args" and "op_kwargs". This guards against future refactors accidentally dropping TaskFlow arguments from template_fields and reintroducing the original MappedArgument type error for TaskGroup.expand(...) with @task.kubernetes_cmd.

Open to discussion!

@boring-cyborg
Copy link

boring-cyborg bot commented Dec 11, 2025

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@boring-cyborg boring-cyborg bot added area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues labels Dec 11, 2025
@potiuk potiuk merged commit 31f953b into apache:main Dec 16, 2025
103 checks passed
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 16, 2025

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

FoxHelms pushed a commit to FoxHelms/airflow that referenced this pull request Dec 17, 2025
Lohith625 pushed a commit to Lohith625/airflow that referenced this pull request Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:cncf-kubernetes Kubernetes (k8s) provider related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Unable to use expand on a TaskGroup containing a @task.kubernetes_cmd task

3 participants