Task SDK: Fix Variable.set/delete swallowing API errors — propagate AirflowRuntimeError to fail the task#68539
Task SDK: Fix Variable.set/delete swallowing API errors — propagate AirflowRuntimeError to fail the task#68539Shushankranjan wants to merge 1 commit into
Conversation
|
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
|
onlyarnav
left a comment
There was a problem hiding this comment.
Could you explain the removal of logging and AirflowRuntimeError workflow from variable.py?
What Changed in
|
| Test | What it asserts |
|---|---|
test_var_set_raises_on_error |
Variable.set() re-raises AirflowRuntimeError when the API rejects the write |
test_var_delete_raises_on_error |
Variable.delete() re-raises AirflowRuntimeError when the API rejects the delete |
The logging import was also removed as a cleanup - it was only there to service the now-gone except block.
Summary: The try/except + logging in set()/delete() was silently eating API errors, letting tasks proceed as if writes succeeded when they hadn't. Removing it makes write failures immediately visible as task failures, consistent with how get() already behaves.
When the Execution API rejects a variable write (any non-2xx response —
e.g. a 403 authorization denial or a server error),
Variable.set()andVariable.delete()were catchingAirflowRuntimeErrorand only loggingit. The task still finished as success and the variable was left
unchanged.
This is inconsistent with
Variable.get(), which already raises on error(and since #66575 even refuses secrets-backend fallback on a 401/403).
Reads fail loudly on denial; writes silently succeeded.
Changes
Variable.set(): Remove thetry/except AirflowRuntimeErrorblockthat swallowed the error. Any API rejection now propagates and fails the
task.
Variable.delete(): Same fix.loggingimport andlogvariable fromvariable.py.test_var_set_raises_on_errorandtest_var_delete_raises_on_errorto cover the error propagation path.
Root cause
closes: #68537
Related: #66575 (fixed the analogous read / secrets-backend path)