Skip to content

Commit c59f4cd

Browse files
Fix TaskSDK swallowing errors when Variable.set() or Variable.delete() fails (#68542)
It was being logged, but no error was returned to the caller.
1 parent 7153240 commit c59f4cd

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

‎task-sdk/src/airflow/sdk/definitions/variable.py‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,9 @@ def get(cls, key: str, default: Any = NOTSET, deserialize_json: bool = False):
6060

6161
@classmethod
6262
def set(cls, key: str, value: Any, description: str | None = None, serialize_json: bool = False) -> None:
63-
from airflow.sdk.exceptions import AirflowRuntimeError
6463
from airflow.sdk.execution_time.context import _set_variable
6564

66-
try:
67-
return _set_variable(key, value, description, serialize_json=serialize_json)
68-
except AirflowRuntimeError as e:
69-
log.exception(e)
65+
_set_variable(key, value, description, serialize_json=serialize_json)
7066

7167
@classmethod
7268
def keys(cls, prefix: str | None = None) -> Sequence[str]:
@@ -94,10 +90,6 @@ def keys(cls, prefix: str | None = None) -> Sequence[str]:
9490

9591
@classmethod
9692
def delete(cls, key: str) -> None:
97-
from airflow.sdk.exceptions import AirflowRuntimeError
9893
from airflow.sdk.execution_time.context import _delete_variable
9994

100-
try:
101-
_delete_variable(key=key)
102-
except AirflowRuntimeError as e:
103-
log.exception(e)
95+
_delete_variable(key=key)

‎task-sdk/tests/task_sdk/definitions/test_variables.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@
2525

2626
from airflow.sdk import Variable
2727
from airflow.sdk.configuration import initialize_secrets_backends
28-
from airflow.sdk.execution_time.comms import GetVariableKeys, PutVariable, VariableKeysResult, VariableResult
28+
from airflow.sdk.exceptions import AirflowRuntimeError, ErrorType
29+
from airflow.sdk.execution_time.comms import (
30+
DeleteVariable,
31+
ErrorResponse,
32+
GetVariableKeys,
33+
PutVariable,
34+
VariableKeysResult,
35+
VariableResult,
36+
)
2937
from airflow.sdk.execution_time.secrets import DEFAULT_SECRETS_SEARCH_PATH_WORKERS
3038

3139
from tests_common.test_utils.config import conf_vars
@@ -89,6 +97,11 @@ def test_var_set(self, key, value, description, serialize_json, mock_supervisor_
8997
),
9098
)
9199

100+
def test_var_delete(self, mock_supervisor_comms):
101+
Variable.delete(key="my_key")
102+
103+
mock_supervisor_comms.send.assert_called_once_with(msg=DeleteVariable(key="my_key"))
104+
92105

93106
class TestVariableKeys:
94107
@pytest.mark.parametrize(
@@ -171,8 +184,6 @@ def test_keys_paginates_when_results_exceed_page_size(self, mock_supervisor_comm
171184
)
172185

173186
def test_keys_raises_on_error_response(self, mock_supervisor_comms):
174-
from airflow.sdk.exceptions import AirflowRuntimeError, ErrorType
175-
from airflow.sdk.execution_time.comms import ErrorResponse
176187

177188
mock_supervisor_comms.send.return_value = ErrorResponse(
178189
error=ErrorType.GENERIC_ERROR, detail={"message": "boom"}

0 commit comments

Comments
 (0)