This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new b528a941546 Fix operators declaring template_fields/template_ext as
bare strings (#70916)
b528a941546 is described below
commit b528a9415462137f068200a616bb80d90f7bbdc7
Author: Y-C <[email protected]>
AuthorDate: Sun Aug 2 05:59:48 2026 +0800
Fix operators declaring template_fields/template_ext as bare strings
(#70916)
A bare string is a sequence of characters, so "chat_id" declares the
fields "c", "h", "a"... rather than "chat_id".
Airflow papers over this for template_fields by wrapping a string in a
list, at the cost of a UserWarning on every task build. template_ext gets
no such fallback: ".bat" expands to (".", "b", "a", "t"), so any templated
value ending in one of those characters is mistaken for a script path and
its contents silently loaded in its place.
Co-authored-by: Eason09053360
<[email protected]>
---
.../airflow/providers/edge3/example_dags/win_notepad.py | 2 +-
.../airflow/providers/edge3/example_dags/win_test.py | 2 +-
.../airflow/providers/telegram/operators/telegram.py | 2 +-
.../tests/unit/telegram/operators/test_telegram.py | 17 ++++++++++++++++-
4 files changed, 19 insertions(+), 4 deletions(-)
diff --git
a/providers/edge3/src/airflow/providers/edge3/example_dags/win_notepad.py
b/providers/edge3/src/airflow/providers/edge3/example_dags/win_notepad.py
index 4f2f0005de4..2c1818d98ae 100644
--- a/providers/edge3/src/airflow/providers/edge3/example_dags/win_notepad.py
+++ b/providers/edge3/src/airflow/providers/edge3/example_dags/win_notepad.py
@@ -43,7 +43,7 @@ if TYPE_CHECKING:
class NotepadOperator(BaseOperator):
"""Example Operator Implementation which starts a ``Notepad.exe`` on
Windows."""
- template_fields: Sequence[str] = "text"
+ template_fields: Sequence[str] = ("text",)
def __init__(self, text: str, **kwargs):
self.text = text
diff --git
a/providers/edge3/src/airflow/providers/edge3/example_dags/win_test.py
b/providers/edge3/src/airflow/providers/edge3/example_dags/win_test.py
index df59265de50..43fd6f40ee5 100644
--- a/providers/edge3/src/airflow/providers/edge3/example_dags/win_test.py
+++ b/providers/edge3/src/airflow/providers/edge3/example_dags/win_test.py
@@ -140,7 +140,7 @@ class CmdOperator(BaseOperator):
template_fields: Sequence[str] = ("command", "env", "cwd")
template_fields_renderers = {"command": "bash", "env": "json"}
- template_ext: Sequence[str] = ".bat"
+ template_ext: Sequence[str] = (".bat",)
subprocess: Popen | None = None
diff --git
a/providers/telegram/src/airflow/providers/telegram/operators/telegram.py
b/providers/telegram/src/airflow/providers/telegram/operators/telegram.py
index 524786582d3..f55f7e1864f 100644
--- a/providers/telegram/src/airflow/providers/telegram/operators/telegram.py
+++ b/providers/telegram/src/airflow/providers/telegram/operators/telegram.py
@@ -103,7 +103,7 @@ class TelegramFileOperator(BaseOperator):
:param telegram_kwargs: Extra args to be passed to telegram client
"""
- template_fields: Sequence[str] = "chat_id"
+ template_fields: Sequence[str] = ("chat_id",)
ui_color = "#FFBA40"
def __init__(
diff --git a/providers/telegram/tests/unit/telegram/operators/test_telegram.py
b/providers/telegram/tests/unit/telegram/operators/test_telegram.py
index d5c41bca997..a1cdd92322c 100644
--- a/providers/telegram/tests/unit/telegram/operators/test_telegram.py
+++ b/providers/telegram/tests/unit/telegram/operators/test_telegram.py
@@ -24,7 +24,7 @@ import telegram
import airflow
from airflow.models import Connection
-from airflow.providers.telegram.operators.telegram import TelegramOperator
+from airflow.providers.telegram.operators.telegram import
TelegramFileOperator, TelegramOperator
TELEGRAM_TOKEN = "xxx:xxx"
@@ -174,3 +174,18 @@ class TestTelegramOperator:
)
operator.render_template_fields({"chat_id": "1234567"})
assert operator.chat_id == "1234567"
+
+
+class TestTelegramFileOperator:
+ def test_should_return_template_fields(self):
+ assert TelegramFileOperator.template_fields == ("chat_id",)
+
+ def test_should_return_templatized_chat_id_field(self):
+ operator = TelegramFileOperator(
+ telegram_conn_id="telegram_default",
+ chat_id="{{ chat_id }}",
+ task_id="telegram",
+ file="/tmp/file.txt",
+ )
+ operator.render_template_fields({"chat_id": "1234567"})
+ assert operator.chat_id == "1234567"