Skip to content

Params Fail to Evaluate In Dag Body #39692

Answered by josh-fell
oliver-helix asked this question in General
Discussion options

You must be logged in to vote

You can use Jinja's include tag to render a file's contents.

For example, using this SQL file;

# dags/sql/default.sql
SELECT 'from a templated file';

and this task definition:

from airflow.models.dag import DAG
from airflow.models.param import Param
from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator

with DAG(
    "generate_password_dag",
    params={"test": Param("default", type="string")},
):
    sql_operator = SQLExecuteQueryOperator(
        task_id="sql_operator",
        sql="{% include 'sql/' ~ params.test ~ '.sql' %}",
        conn_id="postgres",
    )

In the above task definition, ~ is string concatenation in Jinja.

Task log:

@oliver-helix Can you try…

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by josh-fell
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug This is a clearly a bug area:core needs-triage label for new issues that we didn't triage yet
3 participants
Converted from issue

This discussion was converted from issue #39651 on May 17, 2024 16:19.