Skip to content

expand_kwargs does not preserve templates #38745

Description

@alexdrydew

Apache Airflow version

2.8.4

If "Other Airflow 2 version" selected, which one?

No response

What happened?

It looks like expand_kwargs does not preserve templates that are stored in xcom

What you think should happen instead?

I believe in this case templates should not be rendered as this is the behaviour of basic PlainXComArg.resolve and simple .expand as well

How to reproduce

import datetime

from airflow.decorators import dag, task


@task
def some_task():
    return [{"value": "{{ foo }}"}]


@task
def print_task(value):
    print(value)


@dag(
    schedule=None,
    start_date=datetime.datetime(2024, 1, 19),
    catchup=False,
)
def pipeline():
    print_task.expand_kwargs(some_task())


pipeline().test()

This fails with:

jinja2.exceptions.UndefinedError: 'foo' is undefined

Operating System

macOS 14.2

Versions of Apache Airflow Providers

No response

Deployment

Virtualenv installation

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions