Skip to content

Commit b7b6e7a

Browse files
committed
refactor: Check if task exists in render_template_fields of Trigger
1 parent 59981fe commit b7b6e7a

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

  • airflow-core/src/airflow/triggers

airflow-core/src/airflow/triggers/base.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ def _set_context(self, context):
9090
pass
9191

9292
@property
93-
def task(self) -> Operator | None:
94-
if self.task_instance:
95-
return self.task_instance.task
96-
return None
93+
def task(self) -> Operator:
94+
return self.task_instance.task
9795

9896
@property
9997
def task_instance(self) -> TaskInstance | None:
@@ -128,12 +126,13 @@ def render_template_fields(
128126
rendered_content = self.render_template(value, context, jinja_env)
129127
except Exception:
130128
# TODO: Mask the value. Depends on https://github.com/apache/airflow/issues/45438
131-
self.log.exception(
132-
"Exception rendering Jinja template for task '%s', field '%s'. Template: %r",
133-
self.task.task_id,
134-
attr_name,
135-
value,
136-
)
129+
if self.task:
130+
self.log.exception(
131+
"Exception rendering Jinja template for task '%s', field '%s'. Template: %r",
132+
self.task.task_id,
133+
attr_name,
134+
value,
135+
)
137136
raise
138137
else:
139138
setattr(self, attr_name, rendered_content)

0 commit comments

Comments
 (0)