Resolve VariableInterval deadlines safely at DagRun creation - #68917
Resolve VariableInterval deadlines safely at DagRun creation#68917seanghaeli wants to merge 3 commits into
Conversation
7aee60c to
94825ec
Compare
94825ec to
2342c03
Compare
There was a problem hiding this comment.
I did not manage to get to the tests but if I have to be honest, I think this needs a round of polish before a maintainer can review it. Conceptually, it looks correct but there are classic smells of unvetted AI-generated content such as messy code, long commnets/docstrings etc. I would convert it to draft and clean it up before requesting review.
I have left some comments.
56b2666 to
3e4399b
Compare
69649b1 to
4754b7c
Compare
|
@SameerMesiah97 could I get your inputs on the updated version? |
SameerMesiah97
left a comment
There was a problem hiding this comment.
Looks good to me. I just left a few more comments.
A ``DeadlineAlert`` configured with a ``VariableInterval`` is resolved when the
scheduler creates a DagRun, inside ``DAG._process_dagrun_deadline_alerts`` (which
runs under the ``prohibit_commit`` guard). Two problems are fixed:
1. Resolution now goes through the full secrets chain (env vars, configured
secrets backends, then the metadata DB) via a dedicated
``_resolve_variable_interval`` helper, rather than ``Variable.get`` /
``begin_nested``. ``Variable.get`` and a SAVEPOINT release both commit on the
scheduler's session, tripping ``prohibit_commit`` ("UNEXPECTED COMMIT") and
silently dropping deadlines for every scheduled DagRun. The helper passes the
scheduler session through to the metastore backend so the DB read happens
without committing, and reading via the secrets chain (not the variable table
directly) means ``AIRFLOW_VAR_*`` env vars and secrets backends resolve too.
2. Each deadline alert is isolated with a plain ``try``/``except`` (NOT
``begin_nested``). Creating a deadline is auxiliary to creating the DagRun; a
single bad alert -- a missing/invalid backing Variable, or an undecodable
serialized blob -- must never abort the DagRun and stop the DAG scheduling.
``VariableInterval.resolve`` is split into ``resolve`` + ``coerce_to_timedelta``
so the scheduler-side reader reuses the exact same validation (including the
OverflowError -> ValueError translation) without going through ``Variable.get``.
Generated-by: Claude Code (Sonnet/Opus via Claude Code) on behalf of Sean Ghaeli
c176287 to
e1a907b
Compare
ferruzzi
left a comment
There was a problem hiding this comment.
Apparently I reviewed this last week and forgot to submit. Sorry for the delay
| for backend in ensure_secrets_loaded(): | ||
| value = call_secrets_backend_method( | ||
| backend.get_variable, | ||
| team_name=None, |
There was a problem hiding this comment.
Should team_name be hardcoded to None here?? Seems like it should check if there is a team unless I;'m missing something.
Why
This re-introduces the
VariableIntervalresolution portion of #66608.A
DeadlineAlertconfigured with aVariableIntervalis resolved when the scheduler creates a DagRun, insideDAG._process_dagrun_deadline_alerts(which runs under theprohibit_commitguard). Two problems are fixed:Resolution goes through the full secrets chain (env vars, configured secrets backends, then the metadata DB) via a dedicated
_resolve_variable_intervalhelper, rather thanVariable.get/begin_nested.Variable.getand a SAVEPOINT release both commit on the scheduler's session, trippingprohibit_commit(UNEXPECTED COMMIT) and silently dropping deadlines for every scheduled DagRun. The helper passes the scheduler session through to the metastore backend so the DB read does not commit, and reading via the secrets chain (not thevariabletable directly) meansAIRFLOW_VAR_*env vars and secrets-backend-backed Variables resolve too.Each deadline alert is isolated with a plain
try/except(deliberately notbegin_nested, which would commit a SAVEPOINT and trip the same guard). Creating a deadline is auxiliary to creating the DagRun; a single bad alert — a missing/invalid backing Variable, or an undecodable serialized blob — must never abort the DagRun and stop the DAG from scheduling.VariableInterval.resolveis split intoresolve+coerce_to_timedeltaso the scheduler-side reader reuses the exact same validation (including theOverflowError->ValueErrortranslation) without going throughVariable.get.Tests
airflow-core/tests/unit/models/test_dagrun.py: VariableInterval resolves from a real Variable row and from anAIRFLOW_VAR_*env var; a missing Variable and an undecodable alert are isolated (DagRun still created, no Deadline row, error logged).task-sdk/tests/task_sdk/definitions/test_deadline.py:coerce_to_timedeltavalidation (non-integer,<= 0, overflow).Verified locally in Breeze: 8 passed (dagrun deadline/variable) + 14 passed (SDK
TestVariableInterval).Generated-by: Claude Code (Opus via Claude Code) on behalf of Sean Ghaeli