RehanAhmad25 commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3652949263


##########
providers/standard/src/airflow/providers/standard/sensors/time.py:
##########
@@ -62,34 +62,38 @@ def __init__(
         trigger_kwargs: dict[str, Any] | None = None,
         **kwargs,
     ) -> None:
+        if start_from_trigger:
+            warnings.warn(
+                "start_from_trigger is deprecated for TimeSensor and is now 
ignored. The target "
+                "moment is computed fresh from the current wall-clock time on 
every Dag parse, so "
+                "baking it into the serialized trigger arguments made the 
serialized Dag hash change "
+                "on every parse. Use deferrable=True instead, which computes 
the target moment at "
+                "task execution time and does not have this problem.",
+                AirflowProviderDeprecationWarning,
+                stacklevel=2,
+            )
         super().__init__(**kwargs)
 
-        # Create a "date-aware" timestamp that will be used as the 
"target_datetime". This is a requirement
-        # of the DateTimeTrigger
+        self.target_time = target_time
+        self.deferrable = deferrable
+        self.start_from_trigger = False
+        self.end_from_trigger = end_from_trigger
 
-        # Get date considering dag.timezone
+    @property
+    def target_datetime(self) -> datetime.datetime:
+        """Compute the target moment on demand, in the dag's timezone."""
         aware_time = timezone.coerce_datetime(
             datetime.datetime.combine(
-                datetime.datetime.now(self.dag.timezone), target_time, 
self.dag.timezone
+                datetime.datetime.now(self.dag.timezone), self.target_time, 
self.dag.timezone
             )
         )
-
-        # Now that the dag's timezone has made the datetime timezone aware, we 
need to convert to UTC
-        self.target_datetime = timezone.convert_to_utc(aware_time)
-        self.deferrable = deferrable
-        self.start_from_trigger = start_from_trigger
-        self.end_from_trigger = end_from_trigger
-
-        if self.start_from_trigger:
-            self.start_trigger_args.trigger_kwargs = dict(
-                moment=self.target_datetime, 
end_from_trigger=self.end_from_trigger
-            )
+        return timezone.convert_to_utc(aware_time)
 
     def execute(self, context: Context) -> None:
         if self.deferrable:
             self.defer(
                 trigger=DateTimeTrigger(
-                    moment=self.target_datetime,  # This needs to be an aware 
timestamp
+                    moment=self.target_datetime,

Review Comment:
   Good catch, that comment should still be there, it was dropped by accident 
in the refactor, not intentionally. I'll restore it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to