Skip to content

Incorrect rendered template truncation for small max_templated_fields_length config #59877

@amoghrajesh

Description

@amoghrajesh

Apache Airflow version

main (development)

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

No response

What happened?

When AIRFLOW__CORE__MAX_TEMPLATED_FIELD_LENGTH is set to very small values (e.g., 1, 5, 10), the Rendered Templates view in the Airflow UI shows inconsistent and broken truncation behavior.

Let's take 1 as an example.

If we set AIRFLOW__CORE__MAX_TEMPLATED_FIELD_LENGTH=1 and run a task, it causes the Rendered Templates view to display truncated content inconsistently:

  • Some fields show only the truncation suffix without any actual content
  • Some fields are completely empty
  • The truncation suffix itself exceeds the configured max length

What you think should happen instead?

With AIRFLOW__CORE__MAX_TEMPLATED_FIELD_LENGTH=1, each templated field should:

  • Show at least 1 character of the actual value
  • Behave consistently across all field types

How to reproduce

  1. Set export AIRFLOW__CORE__MAX_TEMPLATED_FIELD_LENGTH=1 and run airflow
  2. Create a dag like this one:
from datetime import datetime
from airflow.sdk import DAG
from airflow.providers.standard.operators.bash import BashOperator

with DAG(
    dag_id="test_max_length_1_bug",
    start_date=datetime(2024, 1, 1),
    schedule=None,
    catchup=False,
) as dag:
    task = BashOperator(
        task_id="test_truncation",
        bash_command="echo 'Field 1: {{ params.field1 }}' && echo 'Field 2: {{ params.field2 }}' && echo 'Field 3: {{ params.field3 }}'",
        params={
            "field1": "This is a long string that should be truncated",
            "field2": "Another long string for testing truncation behavior",
            "field3": "Short",
            "nested_dict": {
                "key1": "Long value that needs truncation",
                "key2": "Another long value",
                "key3": "X"
            },
            "list_field": ["Item 1", "Item 2", "Item 3", "Item 4"],
        },
        env={
            "ENV_VAR_1": "Long environment variable value",
            "ENV_VAR_2": "Another long environment variable",
            "ENV_VAR_3": "Short"
        }
    )
  1. Observe rendered templates:
Image

Operating System

MacOS

Versions of Apache Airflow Providers

No response

Deployment

Docker-Compose

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

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions