You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "RehanAhmad25 (via GitHub)" <gi...@apache.org> on 2026/07/15 14:22:50 UTC

[PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

RehanAhmad25 opened a new pull request, #69925:
URL: https://github.com/apache/airflow/pull/69925

    <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   Closes: #69543
   
   ## What does this PR do?
   
   `TimeSensor` computed its target datetime in `__init__`, which runs at DAG parse time using `datetime.now(self.dag.timezone)`. When `start_from_trigger=True`, this value was stored directly in `start_trigger_args.trigger_kwargs`, which is serialized as part of the DAG. Because the value changed on every parse, the serialized DAG hash also changed on every parse, continuously creating new DAG versions.
   
   This PR:
   
   - Raises a `ValueError` when `start_from_trigger=True` is used with `TimeSensor`, since the target moment cannot be safely computed at parse time. `deferrable=True` remains fully supported and unaffected.
   - Changes `target_datetime` into a property that is computed on access instead of being fixed during `__init__`.
   - Updates the `TimeSensor` documentation to describe the actual behavior, which uses the current wall-clock time in the DAG's timezone, instead of the previously documented `data_interval_end`/`run_after`-relative behavior that was never implemented.
   
   
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "RehanAhmad25 (via GitHub)" <gi...@apache.org>.
RehanAhmad25 commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3652951142


##########
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

Review Comment:
   Correct, with the change to a deprecation warning instead of a hard error, `start_from_trigger` will always be `False` now, it can no longer be set to `True` (that path just warns and falls back to `False`). Keeping the attribute itself for backward compatibility, since `TimeSensorAsync` in this same file already uses the same pattern (deprecated flag kept as an inert attribute rather than removed outright).



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior [airflow]

Posted by "github-actions[bot] (via GitHub) via commits" <co...@airflow.apache.org>.
github-actions[bot] commented on PR #69925:
URL: https://github.com/apache/airflow/pull/69925#issuecomment-6673050844

   This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "RehanAhmad25 (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "RehanAhmad25 (via GitHub)" <gi...@apache.org>.
RehanAhmad25 commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3652289102


##########
providers/standard/src/airflow/providers/standard/sensors/time.py:
##########
@@ -62,34 +62,36 @@ def __init__(
         trigger_kwargs: dict[str, Any] | None = None,
         **kwargs,
     ) -> None:
+        if start_from_trigger:
+            raise ValueError(
+                "TimeSensor does not support start_from_trigger=True. The target moment is "
+                "computed fresh from the current wall-clock time on every Dag parse, so baking "
+                "it into the serialized trigger arguments makes 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."
+            )

Review Comment:
   Good point, you're right, a hard error at parse time is too risky here. Updated it: `start_from_trigger=True` now just emits a deprecation warning and gets ignored (falls back to `False`), instead of raising. So existing DAGs using it won't break on upgrade, they'll just see a warning telling them to switch to `deferrable=True`. Updated the test and docs to match. Let me know if that works better.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "RehanAhmad25 (via GitHub)" <gi...@apache.org>.
RehanAhmad25 commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3652958073


##########
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

Review Comment:
   No, it can't be set to True anymore, it'll always be False now. With the switch to a deprecation warning instead of a hard error, passing True just triggers the warning and silently falls back to False. Keeping the attribute itself around for backward compatibility, since TimeSensorAsync in this same file already does the same thing (deprecated flag kept as an inert attribute instead of being removed outright).



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior [airflow]

Posted by "RehanAhmad25 (via GitHub)" <gi...@apache.org>.
RehanAhmad25 commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3772283627


##########
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

Review Comment:
   Good point, updated it: `start_from_trigger` is now a property with a setter instead of a plain attribute. Reading it still always returns `False`, but setting it (whether at construction or afterward, e.g. `op.start_from_trigger = True`) now emits the same deprecation warning each time rather than only warning once and then silently ignoring further attempts. Tests updated to cover both the constructor path and direct assignment after construction.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "RehanAhmad25 (via GitHub)" <gi...@apache.org>.
RehanAhmad25 commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3652951142


##########
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

Review Comment:
   Correct, with the change to a deprecation warning instead of a hard error, `start_from_trigger` will always be `False` now, it can no longer be set to `True` (that path just warns and falls back to `False`). Keeping the attribute itself for backward compatibility, since `TimeSensorAsync` in this same file already uses the same pattern (deprecated flag kept as an inert attribute rather than removed outright).



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior [airflow]

Posted by "Vamsi-klu (via GitHub)" <gi...@apache.org>.
Vamsi-klu commented on PR #69925:
URL: https://github.com/apache/airflow/pull/69925#issuecomment-5463684991

   @RehanAhmad25 @uranusjr I posted a comparison on https://github.com/apache/airflow/issues/69543 recommending #69746 (keep start_from_trigger, lazy TimeOfDayTrigger) over this PR (deprecate/ignore the flag). That matches @uranusjr's Aug 17 comment on the issue and @potiuk's earlier request not to drop a documented API without a major bump.
   
   If that lands, this PR can be closed as superseded. Your Aug 17 note that you would open a new lazy-resolution PR is appreciated; #69746 already implements that design, so a third PR would duplicate review.
   
   
   ---
   Drafted-by: Cursor Grok 4.6; reviewed by @Vamsi-klu before posting


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior [airflow]

Posted by "RehanAhmad25 (via GitHub)" <gi...@apache.org>.
RehanAhmad25 commented on PR #69925:
URL: https://github.com/apache/airflow/pull/69925#issuecomment-5278891824

   > This and #69746 fix the same thing in different ways. We should first figure out the correct approach in the issue.
   
   Agreed, let's settle this on the issue so it's not split across two threads.
   
   For what it's worth, my read on the tradeoff: #69746's TimeOfDayTrigger genuinely fixes more than mine does, it caught and fixed the class-level `start_trigger_args` mutation bug independently, which mine only sidesteps (the buggy code path becomes dead code once `start_from_trigger` is deprecated, but I didn't find that bug myself). That's a real point in its favor.
   
   My case for the simpler deprecation approach: `start_from_trigger` avoids one worker-slot poke/defer cycle by starting the sensor directly on the triggerer, a fairly narrow optimization. Preserving it costs a new trigger class, lazy-resolution logic, and DST edge case handling (spring-forward gaps, fall-back ambiguity) that's now permanent surface area to maintain and could itself grow bugs over time. Given how narrow the benefit is, I think removing it is proportionate, but I'm not tied to that if the consensus lands the other way, happy to adapt or step back from this fix if #69746 is the preferred direction. I'll post this same comparison on the issue.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3652300711


##########
providers/standard/src/airflow/providers/standard/sensors/time.py:
##########
@@ -101,10 +105,9 @@ def execute_complete(self, context: Context, event: Any = None) -> None:
         return None
 
     def poke(self, context: Context) -> bool:
-        self.log.info("Checking if the time (%s) has come", self.target_datetime)
-
-        # self.target_date has been converted to UTC, so we do not need to convert timezone
-        return timezone.utcnow() > self.target_datetime
+        target_datetime = self.target_datetime
+        self.log.info("Checking if the time (%s) has come", target_datetime)
+        return timezone.utcnow() > target_datetime

Review Comment:
   This change doesn’t seem to be meaningful? (Unless it’s doing a race condition)
   
   I’d revert 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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior [airflow]

Posted by "RehanAhmad25 (via GitHub) via commits" <co...@airflow.apache.org>.
RehanAhmad25 commented on PR #69925:
URL: https://github.com/apache/airflow/pull/69925#issuecomment-6673718941

   This PR is marked as Stale, Closing this. Will reopen if required.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3652304819


##########
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:
   Is the comment no longer valid?



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on PR #69925:
URL: https://github.com/apache/airflow/pull/69925#issuecomment-5259837204

   This and https://github.com/apache/airflow/pull/69746 fix the same thing in different ways. We should first figure out the correct approach in the issue.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior [airflow]

Posted by "RehanAhmad25 (via GitHub)" <gi...@apache.org>.
RehanAhmad25 commented on PR #69925:
URL: https://github.com/apache/airflow/pull/69925#issuecomment-5463997864

   @Vamsi-klu  I went through your PR pretty thoroughly and didn’t find any major issues that I felt needed to be flagged.
   
   Since your PR already explores the lazy-resolution approach, opening another PR from my side would essentially duplicate the same direction of work and could make it harder for the maintainers to review and decide between overlapping PRs. That’s why I didn’t open a separate lazy-resolution PR.
   
   Regarding @uranusjr’s earlier review, my understanding was that the preference was to try fixing the underlying `start_from_trigger` issue first, rather than deciding to remove the feature outright. Since it’s still not completely settled whether the feature can/should be retained, I’ve kept my PR open for now.
   
   If #69746 ends up being the preferred approach and the feature is retained, I’m absolutely fine with my PR being superseded and closed. I just didn’t want to prematurely close it while the direction is still being worked out.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #69925:
URL: https://github.com/apache/airflow/pull/69925#issuecomment-4981666630

   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our [Contributors' Guide](https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (ruff, mypy and type annotations). Our [prek-hooks]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-prek-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example Dag that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
   - Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3652304308


##########
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

Review Comment:
   Can this attribute be removed if it’s always False? And can it be set to True?



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "RehanAhmad25 (via GitHub)" <gi...@apache.org>.
RehanAhmad25 commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3652980277


##########
providers/standard/src/airflow/providers/standard/sensors/time.py:
##########
@@ -101,10 +105,9 @@ def execute_complete(self, context: Context, event: Any = None) -> None:
         return None
 
     def poke(self, context: Context) -> bool:
-        self.log.info("Checking if the time (%s) has come", self.target_datetime)
-
-        # self.target_date has been converted to UTC, so we do not need to convert timezone
-        return timezone.utcnow() > self.target_datetime
+        target_datetime = self.target_datetime
+        self.log.info("Checking if the time (%s) has come", target_datetime)
+        return timezone.utcnow() > target_datetime

Review Comment:
   This one's intentional, your parenthetical guess is right. target_datetime is now a computed property (calls datetime.now() fresh on every access), so calling self.target_datetime twice in this method could return two slightly different instants if the wall clock ticks past the target moment between the log call and the comparison. Storing it in a local variable once guarantees the logged value and the compared value are the same instant. I'd like to keep this as-is rather than revert, let me know if you still see it differently.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "RehanAhmad25 (via GitHub)" <gi...@apache.org>.
RehanAhmad25 commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3652979915


##########
providers/standard/src/airflow/providers/standard/sensors/time.py:
##########
@@ -101,10 +105,9 @@ def execute_complete(self, context: Context, event: Any = None) -> None:
         return None
 
     def poke(self, context: Context) -> bool:
-        self.log.info("Checking if the time (%s) has come", self.target_datetime)
-
-        # self.target_date has been converted to UTC, so we do not need to convert timezone
-        return timezone.utcnow() > self.target_datetime
+        target_datetime = self.target_datetime
+        self.log.info("Checking if the time (%s) has come", target_datetime)
+        return timezone.utcnow() > target_datetime

Review Comment:
   This one's intentional, not cosmetic, your parenthetical guess is right. target_datetime is now a computed property (calls datetime.now() fresh on every access), so calling self.target_datetime twice in this method could return two slightly different instants if the wall clock ticks past the target moment between the log call and the comparison. Storing it in a local variable once guarantees the logged value and the compared value are the same instant. I'd like to keep this as-is rather than revert, let me know if you still see it differently.



##########
providers/standard/src/airflow/providers/standard/sensors/time.py:
##########
@@ -101,10 +105,9 @@ def execute_complete(self, context: Context, event: Any = None) -> None:
         return None
 
     def poke(self, context: Context) -> bool:
-        self.log.info("Checking if the time (%s) has come", self.target_datetime)
-
-        # self.target_date has been converted to UTC, so we do not need to convert timezone
-        return timezone.utcnow() > self.target_datetime
+        target_datetime = self.target_datetime
+        self.log.info("Checking if the time (%s) has come", target_datetime)
+        return timezone.utcnow() > target_datetime

Review Comment:
   This one's intentional, not cosmetic, your parenthetical guess is right. target_datetime is now a computed property (calls datetime.now() fresh on every access), so calling self.target_datetime twice in this method could return two slightly different instants if the wall clock ticks past the target moment between the log call and the comparison. Storing it in a local variable once guarantees the logged value and the compared value are the same instant. I'd like to keep this as-is rather than revert, let me know if you still see it differently.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior-Closes : #69543 [airflow]

Posted by "aaron-y-chen (via GitHub)" <gi...@apache.org>.
aaron-y-chen commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3652051480


##########
providers/standard/src/airflow/providers/standard/sensors/time.py:
##########
@@ -62,34 +62,36 @@ def __init__(
         trigger_kwargs: dict[str, Any] | None = None,
         **kwargs,
     ) -> None:
+        if start_from_trigger:
+            raise ValueError(
+                "TimeSensor does not support start_from_trigger=True. The target moment is "
+                "computed fresh from the current wall-clock time on every Dag parse, so baking "
+                "it into the serialized trigger arguments makes 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."
+            )

Review Comment:
   I'm afraid this could cause a backward compatibility issue. Perhaps we should not raise an error directly in the initialization phase.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior [airflow]

Posted by "RehanAhmad25 (via GitHub)" <gi...@apache.org>.
RehanAhmad25 commented on PR #69925:
URL: https://github.com/apache/airflow/pull/69925#issuecomment-5278968484

   > This and #69746 fix the same thing in different ways. We should first figure out the correct approach in the issue.
   
   Agreed, let's settle this on the issue so it's not split across two threads.
   
   For what it's worth, my read on the tradeoff: #69746's TimeOfDayTrigger genuinely fixes more than mine does, it caught and fixed the class-level `start_trigger_args` mutation bug independently, which mine only sidesteps (the buggy code path becomes dead code once `start_from_trigger` is deprecated, but I didn't find that bug myself). That's a real point in its favor.
   
   My case for the simpler deprecation approach: `start_from_trigger` avoids one worker-slot poke/defer cycle by starting the sensor directly on the triggerer, a fairly narrow optimization. Preserving it costs a new trigger class, lazy-resolution logic, and DST edge case handling (spring-forward gaps, fall-back ambiguity) that's now permanent surface area to maintain and could itself grow bugs over time. Given how narrow the benefit is, I think removing it is proportionate, but I'm not tied to that if the consensus lands the other way, happy to adapt or step back from this fix if #69746 is the preferred direction.
   
   For reference, the current state on this PR: `start_from_trigger` is now a property (always reads `False`) with a setter that emits a deprecation warning on any assignment, at construction or afterward, so nothing silently gets ignored without a signal. I'll post this same comparison on the issue.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #69925:
URL: https://github.com/apache/airflow/pull/69925#discussion_r3757230422


##########
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

Review Comment:
   Keeping the value is a good idea, but I don’t like it being an attribute since the user would try to change it and see it’s silently ignored. I would change it to a property instead (with a deprecation warning) so setting it emits an error.



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix TimeSensor start_from_trigger behavior [airflow]

Posted by "RehanAhmad25 (via GitHub) via commits" <co...@airflow.apache.org>.
RehanAhmad25 closed pull request #69925: Fix TimeSensor start_from_trigger behavior
URL: https://github.com/apache/airflow/pull/69925


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org