From 52bca8cd99035942448ab8b8cb930cef9438e1f1 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Wed, 30 Aug 2023 22:57:19 +0800 Subject: [PATCH] fix(sensors): move trigger initialization from __init___ to execute in https://github.com/apache/airflow/pull/33403, we move trigger initialization to __init__ which causes a failure for one uses template variable --- airflow/sensors/date_time.py | 4 ++-- airflow/sensors/time_sensor.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/airflow/sensors/date_time.py b/airflow/sensors/date_time.py index f1a61540c1f9..65880ebb9e75 100644 --- a/airflow/sensors/date_time.py +++ b/airflow/sensors/date_time.py @@ -89,11 +89,11 @@ class DateTimeSensorAsync(DateTimeSensor): def __init__(self, **kwargs) -> None: super().__init__(**kwargs) - self.trigger = DateTimeTrigger(moment=timezone.parse(self.target_time)) def execute(self, context: Context): + trigger = DateTimeTrigger(moment=timezone.parse(self.target_time)) self.defer( - trigger=self.trigger, + trigger=trigger, method_name="execute_complete", ) diff --git a/airflow/sensors/time_sensor.py b/airflow/sensors/time_sensor.py index 0701a1c24480..4a7f2e9d48d7 100644 --- a/airflow/sensors/time_sensor.py +++ b/airflow/sensors/time_sensor.py @@ -71,11 +71,11 @@ def __init__(self, *, target_time, **kwargs): ) self.target_datetime = timezone.convert_to_utc(aware_time) - self.trigger = DateTimeTrigger(moment=self.target_datetime) def execute(self, context: Context): + trigger = DateTimeTrigger(moment=self.target_datetime) self.defer( - trigger=self.trigger, + trigger=trigger, method_name="execute_complete", )