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

[PR] Fix GKEStartPodOperator ignoring execution_timeout when deferrable [airflow]

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

   ## Summary
   
   Fixes #71514.
   
   `GKEStartPodOperator` did not respect `execution_timeout` when
   `deferrable=True` because its custom `invoke_defer_method` did not
   propagate the execution deadline to `GKEStartPodTrigger`.
   
   ### What changed
   
   - Translate `execution_timeout` into an absolute `_execution_deadline`
     anchored to the task instance `start_date`.
   - Pass the deadline through `trigger_kwargs` to `GKEStartPodTrigger`.
   - Add a buffered `defer.timeout` backstop so the trigger can emit its
     timeout event before the framework timeout fires.
   - Preserve `trigger_kwargs` in `GKEStartPodTrigger.serialize()` so the
     deadline survives trigger serialization/restarts.
   - Add regression tests covering deadline propagation, no-timeout
     behavior, existing `trigger_kwargs`, and trigger serialization.
   
   ### Testing
   
   - `TestGKEStartPodOperator`: 16 passed
   - `GKEStartPodTrigger` serialization test: passed
   - Ruff format/check: passed
   
   One broader trigger test run encountered an unrelated local
   `ModuleNotFoundError: airflow_shared` in the test infrastructure.
   The affected serialization test and all operator tests for this change
   passed successfully.


-- 
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 GKEStartPodOperator ignoring execution_timeout when deferrable [airflow]

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


##########
providers/google/src/airflow/providers/google/cloud/operators/kubernetes_engine.py:
##########
@@ -799,6 +800,19 @@ def invoke_defer_method(
         on_finish_action = self.on_finish_action
         if type(on_finish_action) is str and self.on_finish_action not in [i.value for i in OnFinishAction]:
             on_finish_action = self.on_finish_action.split(".")[-1].lower()  # type: ignore[assignment]
+
+        # Anchor on ti.start_date so the deadline survives re-deferrals.
+        trigger_kwargs = dict(self.trigger_kwargs or {})
+        defer_timeout: datetime.timedelta | None = None
+        if self.execution_timeout is not None and context is not None:

Review Comment:
   It has already been fixed upstream: #67229



-- 
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 GKEStartPodOperator ignoring execution_timeout when deferrable [airflow]

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


##########
providers/google/tests/unit/google/cloud/operators/test_kubernetes_engine.py:
##########
@@ -1060,12 +1061,145 @@ def test_invoke_defer_method(
             logging_interval=None,
             last_log_time=mock_last_log_time,
             use_dns_endpoint=False,
+            trigger_kwargs={},
         )
         mock_defer.assert_called_once_with(
             trigger=mock_trigger.return_value,
             method_name="trigger_reentry",
+            timeout=None,
         )
 
+    @mock.patch(GKE_OPERATORS_PATH.format("GKEStartPodOperator.defer"))
+    @mock.patch(GKE_OPERATORS_PATH.format("GKEClusterAuthDetails.fetch_cluster_info"))
+    @mock.patch(GKE_OPERATORS_PATH.format("GKEHook"))
+    @mock.patch(GKE_OPERATORS_PATH.format("GKEStartPodTrigger"))
+    @mock.patch(GKE_OPERATORS_PATH.format("timezone.utcnow"))
+    def test_invoke_defer_method_passes_execution_deadline_when_execution_timeout_set(

Review Comment:
   These three tests share about 25 lines of operator setup. They differ only in `execution_timeout`, the pre-existing `trigger_kwargs`, the frozen time, and the expected values. AGENTS.md says: *"Use `@pytest.mark.parametrize` for multiple similar inputs — consolidate tests that only differ in input/expected values into a single parametrized test."*
   
   When you consolidate them, please also add a case for the `max(remaining, 0)` clamp at `kubernetes_engine.py:814`: freeze the time after the deadline and expect `timeout == datetime.timedelta(seconds=60)`. No test covers that branch now, and AGENTS.md asks that *"Every changed or added behaviour must have a test."*



##########
providers/google/tests/unit/google/cloud/operators/test_kubernetes_engine.py:
##########
@@ -1060,12 +1061,145 @@ def test_invoke_defer_method(
             logging_interval=None,
             last_log_time=mock_last_log_time,
             use_dns_endpoint=False,
+            trigger_kwargs={},
         )
         mock_defer.assert_called_once_with(
             trigger=mock_trigger.return_value,
             method_name="trigger_reentry",
+            timeout=None,
         )
 
+    @mock.patch(GKE_OPERATORS_PATH.format("GKEStartPodOperator.defer"))
+    @mock.patch(GKE_OPERATORS_PATH.format("GKEClusterAuthDetails.fetch_cluster_info"))
+    @mock.patch(GKE_OPERATORS_PATH.format("GKEHook"))
+    @mock.patch(GKE_OPERATORS_PATH.format("GKEStartPodTrigger"))
+    @mock.patch(GKE_OPERATORS_PATH.format("timezone.utcnow"))
+    def test_invoke_defer_method_passes_execution_deadline_when_execution_timeout_set(
+        self, mock_utcnow, mock_trigger, mock_cluster_hook, mock_fetch_cluster_info, mock_defer
+    ):
+        """
+        ``execution_timeout`` is converted into an absolute ``_execution_deadline``
+        anchored on ``ti.start_date`` and propagated to the trigger via
+        ``trigger_kwargs``.
+        """
+        import time_machine

Review Comment:
   `import time_machine` is inside the test body here and again at line 1170. Please move it to the module imports. AGENTS.md says: *"Imports at top of file. Valid exceptions: circular imports, lazy loading for worker isolation, `TYPE_CHECKING` blocks."* None of those exceptions applies to a test module.



-- 
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 GKEStartPodOperator ignoring execution_timeout when deferrable [airflow]

Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 merged PR #71528:
URL: https://github.com/apache/airflow/pull/71528


-- 
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 GKEStartPodOperator ignoring execution_timeout when deferrable [airflow]

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


##########
providers/google/src/airflow/providers/google/cloud/operators/kubernetes_engine.py:
##########
@@ -799,6 +800,19 @@ def invoke_defer_method(
         on_finish_action = self.on_finish_action
         if type(on_finish_action) is str and self.on_finish_action not in [i.value for i in OnFinishAction]:
             on_finish_action = self.on_finish_action.split(".")[-1].lower()  # type: ignore[assignment]
+
+        # Anchor on ti.start_date so the deadline survives re-deferrals.
+        trigger_kwargs = dict(self.trigger_kwargs or {})

Review Comment:
   Yes. The deadline is absolute: `ti.start_date + execution_timeout`, stored as `trigger_kwargs["_execution_deadline"]`.



-- 
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 GKEStartPodOperator ignoring execution_timeout when deferrable [airflow]

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

   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 GKEStartPodOperator ignoring execution_timeout when deferrable [airflow]

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


##########
providers/google/src/airflow/providers/google/cloud/operators/kubernetes_engine.py:
##########
@@ -799,6 +800,25 @@ def invoke_defer_method(
         on_finish_action = self.on_finish_action
         if type(on_finish_action) is str and self.on_finish_action not in [i.value for i in OnFinishAction]:
             on_finish_action = self.on_finish_action.split(".")[-1].lower()  # type: ignore[assignment]
+
+        # Translate ``execution_timeout`` into an absolute deadline plumbed to

Review Comment:
   Thanks! I've reduced the comments to focus on the reasoning rather than restating the implementation. The changes are pushed in the latest commit.



-- 
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 GKEStartPodOperator ignoring execution_timeout when deferrable [airflow]

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


##########
providers/google/src/airflow/providers/google/cloud/operators/kubernetes_engine.py:
##########
@@ -799,6 +800,19 @@ def invoke_defer_method(
         on_finish_action = self.on_finish_action

Review Comment:
   Yes, the same way `KubernetesPodOperator` does, as `GKEStartPodOperator` does not override `trigger_reentry`.



-- 
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 GKEStartPodOperator ignoring execution_timeout when deferrable [airflow]

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


##########
providers/google/src/airflow/providers/google/cloud/operators/kubernetes_engine.py:
##########
@@ -799,6 +800,25 @@ def invoke_defer_method(
         on_finish_action = self.on_finish_action
         if type(on_finish_action) is str and self.on_finish_action not in [i.value for i in OnFinishAction]:
             on_finish_action = self.on_finish_action.split(".")[-1].lower()  # type: ignore[assignment]
+
+        # Translate ``execution_timeout`` into an absolute deadline plumbed to

Review Comment:
   Can you please reduce the comments, as not to just restate what the code is doing?



-- 
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 GKEStartPodOperator ignoring execution_timeout when deferrable [airflow]

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


##########
providers/google/src/airflow/providers/google/cloud/operators/kubernetes_engine.py:
##########
@@ -799,6 +800,19 @@ def invoke_defer_method(
         on_finish_action = self.on_finish_action
         if type(on_finish_action) is str and self.on_finish_action not in [i.value for i in OnFinishAction]:
             on_finish_action = self.on_finish_action.split(".")[-1].lower()  # type: ignore[assignment]
+
+        # Anchor on ti.start_date so the deadline survives re-deferrals.
+        trigger_kwargs = dict(self.trigger_kwargs or {})

Review Comment:
   Does the operator calculate the remaining time (execution_timeout - (utcnow() - task_instance.start_date)) before yielding self.defer(...)?



##########
providers/google/src/airflow/providers/google/cloud/operators/kubernetes_engine.py:
##########
@@ -799,6 +800,19 @@ def invoke_defer_method(
         on_finish_action = self.on_finish_action

Review Comment:
   If the trigger yields a timeout event or fails the task, does the operator or trigger clean up the Kubernetes/GKE pod?



##########
providers/google/src/airflow/providers/google/cloud/operators/kubernetes_engine.py:
##########
@@ -799,6 +800,19 @@ def invoke_defer_method(
         on_finish_action = self.on_finish_action
         if type(on_finish_action) is str and self.on_finish_action not in [i.value for i in OnFinishAction]:
             on_finish_action = self.on_finish_action.split(".")[-1].lower()  # type: ignore[assignment]
+
+        # Anchor on ti.start_date so the deadline survives re-deferrals.
+        trigger_kwargs = dict(self.trigger_kwargs or {})
+        defer_timeout: datetime.timedelta | None = None
+        if self.execution_timeout is not None and context is not None:

Review Comment:
   Is this handled at the GKEStartPodOperator level when it should instead be fixed upstream in cncf-kubernetes's KubernetesPodOperator / GKEPodTrigger / KubernetesPodTrigger? If KPO has the same bug, fixing only GKE leads to fragmentation.



-- 
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 GKEStartPodOperator ignoring execution_timeout when deferrable [airflow]

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

   Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional 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