Uh oh!
There was an error while loading. Please reload this page.
Resolve VariableInterval deadlines safely at DagRun creation - #68917
Resolve VariableInterval deadlines safely at DagRun creation#68917seanghaeli wants to merge 8 commits into
Conversation
7aee60c to
94825ecCompare94825ec to
2342c03CompareThere 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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
56b2666 to
3e4399bCompare69649b1 to
4754b7cCompareseanghaeli
commented
Jul 29, 2026
@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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
c176287 to
e1a907bCompare
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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 Ghaelif9ee1dc to
707ef13Compare
ferruzzi
left a comment
There was a problem hiding this comment.
Looks like my concerns have all been addressed. LGTM
There was a problem hiding this comment.
I'm sorry about this, there are now eight PRs all interacting with the Deadlines code and I'm trying to untangle the conflicts before they get worse. #71802 is approved and needs to be merged before this one because it also blocks a few other fixes, but it is going to kind of pull the rug out from under you a bit on this.
Once it merges, dag.py checks isinstance(interval, SerializedVariableInterval) and no longer imports VariableInterval at all. That means:
You can drop
_resolve_variable_interval. #71968 adds an optional keyword-only session toVariable.get, soSerializedVariableInterval.resolve(session=session)covers it without duplicating the backend walk. Your comment there already points at #71801, which is the issue #71968 fixes.coerce_to_timedeltathen loses its only caller, so that can be dropped along with the relatedtest_coerce_to_timedelta_invalid. TheOverflowErrortoValueErrortranslation is a real improvement nobody else hit on, but it needs to live where the live path actually runs, so wrap thereturn timedelta(seconds=seconds)at the end of the newSerializedVariableInterval.resolve()inairflow-core/src/airflow/serialization/definitions/deadline.py, alongside theint()cast. Then add a "too large" case totest_resolve_invalidwhich #71802 adds inairflow-core/tests/unit/serialization/definitions/test_deadline.py.The seconds <= 0 guard is the one real conflict. An interval can be negative so that check is a distinct bug. Please drop the guard along with the ("0", "must be > 0") and ("-5", "must be > 0") test cases.
Side note: The per-alert try/except isolation is good and nobody else is doing that. It may turn out to be one of the most valuable additions in your PR.
One thing to check: #71287 is doing failure isolation with savepoints around DagRun creation. Your comment says you chose a plain try/except over session.begin_nested() deliberately, so you may already have looked, but the two haven't been cross-referenced anywhere that I can tell.
Overall, it should result in a smaller PR for you, trimming out some redundant (and conflicting) code, not a rewrite.
I am also submitting this as a "Request changes" so it blocks merging out of order and doesn't screw up the other PRs. Unblock conditions: #71802 must merge first, this PR must be merged on top of that one, and the above changes need to be made. Once this one merges, It will unblock #71968 which will have to rebase on top of this and get some tweaks.
| if deadline_time is not None: | ||
| session.add( | ||
| Deadline( | ||
| deadline_time=deadline_time, | ||
| callback=deserialized_deadline_alert.callback, | ||
| dagrun_id=orm_dagrun.id, | ||
| deadline_alert_id=deadline_alert.id, | ||
| dag_id=orm_dagrun.dag_id, | ||
| bundle_name=orm_dagrun.dag_model.bundle_name, | ||
| ) | ||
| ) | ||
| ) | ||
| team_name = ( | ||
| DagModel.get_team_name(self.dag_id, session=session) | ||
| if airflow_conf.getboolean("core", "multi_team") | ||
| else None | ||
| ) | ||
| stats.incr( | ||
| "deadline_alerts.deadline_created", | ||
| tags=prune_dict({"dag_id": self.dag_id, "team_name": team_name}), | ||
| ) | ||
| stats.incr("deadline_alerts.deadline_created", tags=metrics_tags) |
There was a problem hiding this comment.
You are going to end up having to rebase on top of a couple of other PRs that need to land before this one. I'm trying to make that future rebase a bit easier here.
#71767 has an elif branch right after the stats.incr you have on L800. If you can add that here, it should ease your merge pain later:
stats.incr("deadline_alerts.deadline_created", tags=metrics_tags)
elifrequired_dagrun_column:= {
SerializedReferenceModels.DagRunLogicalDateDeadline: "logical_date",
SerializedReferenceModels.DagRunQueuedAtDeadline: "queued_at",
}.get(type(deserialized_deadline_alert.reference)):
log.warning(
"skipping deadline alert because the deadline reference evaluated to None",
dag_id=self.dag_id,
run_id=orm_dagrun.run_id,
deadline_alert_id=deadline_alert.id,
reference_type=deserialized_deadline_alert.reference.reference_name,
required_dagrun_column=required_dagrun_column,
)That PR also adds two tests in airflow-core/tests/unit/models/test_dagrun.py that you'll want to pull over which cover that branch. That can wait till the merge but may be easier to just paste it over now since you are copying this over.
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