Skip to content

Allow use of callable for template_fields for TaskFlow API tasks #44819

@matthewblock

Description

@matthewblock

Description

PR #37028 in Airflow 2.10.0 introduced the ability to pass a Python callable to templateable fields, instead of a Jinja templated string:

https://www.astronomer.io/docs/learn/templating/#use-a-python-callable-for-template-fields

In Airflow 2.10+ it is possible to pass a Python callable to templateable fields. This is especially useful when the parameter value is created using complex operations that might not be possible or are hard to read in Jinja.

However, this feature doesn't seem to work for @task.* decorated tasks.

IMO it doesn't make sense to introduce a new feature that only works with the old style of tasks.

This feature is to make the new Python callable templating work for @task decorated TaskFlow API tasks.

Use case/motivation

I want to specify a Python function for a templated field, instead of a Jinja templated string, for the reasons mentioned in the linked PR. For complex logic, it's much easier to implement and read Jinja rendering functions than a Jinja templated string.

Related issues

#35844
#37028

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions