This is an automated email from the ASF dual-hosted git repository.
dabla pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 7eee2f0ae88 Pass timeout to defer() in MSGraphSensor (#62157) (#62241)
7eee2f0ae88 is described below
commit 7eee2f0ae88f21342e35dcd07e3cf67f5c59f9d5
Author: Subham <[email protected]>
AuthorDate: Wed Mar 11 01:43:02 2026 +0530
Pass timeout to defer() in MSGraphSensor (#62157) (#62241)
This PR ensures that the timeout parameter is correctly passed to the
defer() method in MSGraphSensor. Previously, timeout was not propagated, which
could lead to the sensor waiting indefinitely when deferring.
Related issues/PRs:
• Closes #62157
• Supersedes #62241
Notes:
• Improves reliability of deferrable sensors by respecting
the configured timeout.
---
.../providers/microsoft/azure/sensors/msgraph.py | 4 +++-
.../tests/unit/microsoft/azure/sensors/test_msgraph.py | 18 +++++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git
a/providers/microsoft/azure/src/airflow/providers/microsoft/azure/sensors/msgraph.py
b/providers/microsoft/azure/src/airflow/providers/microsoft/azure/sensors/msgraph.py
index 040ccac0bb5..103fb1d1b45 100644
---
a/providers/microsoft/azure/src/airflow/providers/microsoft/azure/sensors/msgraph.py
+++
b/providers/microsoft/azure/src/airflow/providers/microsoft/azure/sensors/msgraph.py
@@ -18,6 +18,7 @@
from __future__ import annotations
from collections.abc import Callable, Sequence
+from datetime import timedelta
from typing import TYPE_CHECKING, Any
from airflow.providers.common.compat.sdk import AirflowException,
BaseSensorOperator
@@ -27,7 +28,6 @@ from airflow.providers.microsoft.azure.operators.msgraph
import execute_callable
from airflow.providers.microsoft.azure.triggers.msgraph import MSGraphTrigger,
ResponseSerializer
if TYPE_CHECKING:
- from datetime import timedelta
from io import BytesIO
from msgraph_core import APIVersion
@@ -183,9 +183,11 @@ class MSGraphSensor(BaseSensorOperator):
return result
+ # Re-defer with timeout so Airflow enforces the sensor timeout
natively
self.defer(
trigger=TimeDeltaTrigger(self.retry_delay),
method_name=self.retry_execute.__name__,
+ timeout=timedelta(seconds=self.timeout) if self.timeout is
not None else None,
)
return None
diff --git
a/providers/microsoft/azure/tests/unit/microsoft/azure/sensors/test_msgraph.py
b/providers/microsoft/azure/tests/unit/microsoft/azure/sensors/test_msgraph.py
index f3df0e882ae..66f439ba722 100644
---
a/providers/microsoft/azure/tests/unit/microsoft/azure/sensors/test_msgraph.py
+++
b/providers/microsoft/azure/tests/unit/microsoft/azure/sensors/test_msgraph.py
@@ -17,8 +17,9 @@
from __future__ import annotations
import json
-from datetime import datetime
+from datetime import datetime, timedelta
from os.path import dirname
+from unittest.mock import patch
import pytest
@@ -141,3 +142,18 @@ class TestMSGraphSensor:
for template_field in MSGraphSensor.template_fields:
getattr(sensor, template_field)
+
+ def test_execute_complete_passes_timeout_to_defer(self):
+ sensor = MSGraphSensor(
+ task_id="check_timeout",
+ conn_id="powerbi",
+ url="myorg/admin/workspaces/scanStatus/{scanId}",
+ timeout=10,
+ )
+
+ with patch.object(sensor, "defer") as mock_defer:
+ sensor.execute_complete(
+ context={}, event={"status": "success", "response":
json.dumps({"status": "running"})}
+ )
+ mock_defer.assert_called_once()
+ assert mock_defer.call_args.kwargs["timeout"] ==
timedelta(seconds=10)