Skip to content

Commit 513622e

Browse files
authored
Show not supported exception for SyncCallback at Dag author time (apache#55390)
Currently, if a user uses SyncCallback for a DeadlineAlert without reading docs, they will not find out that they're not currently supported until the deadline is missed. So, this is just a quality-of-life change to alert the user at Dag author time.
1 parent ab6ebf7 commit 513622e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

task-sdk/src/airflow/sdk/definitions/deadline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ def __init__(
5555
):
5656
self.reference = reference
5757
self.interval = interval
58+
59+
if not isinstance(callback, AsyncCallback):
60+
raise ValueError(f"Callbacks of type {type(callback).__name__} are not currently supported")
5861
self.callback = callback
5962

6063
def __eq__(self, other: object) -> bool:

task-sdk/tests/task_sdk/definitions/test_deadline.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ def test_deadline_alert_in_set(self):
158158
alert_set = {alert1, alert2}
159159
assert len(alert_set) == 1
160160

161+
def test_deadline_alert_unsupported_callback(self):
162+
with pytest.raises(ValueError, match="Callbacks of type SyncCallback are not currently supported"):
163+
DeadlineAlert(
164+
reference=DeadlineReference.DAGRUN_QUEUED_AT,
165+
interval=timedelta(hours=1),
166+
callback=SyncCallback(TEST_CALLBACK_PATH),
167+
)
168+
161169

162170
class TestCallback:
163171
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)