ramitkataria commented on code in PR #75363:
URL: https://github.com/apache/airflow/pull/75363#discussion_r4465307231
##########
airflow-core/src/airflow/models/deadline.py:
##########
@@ -266,64 +266,21 @@ def handle_miss(self, session: Session):
"""Handle a missed deadline by queueing the callback."""
from airflow.models.dag import DagModel # Avoids circular import
- def get_simple_context():
- from airflow.api_fastapi.core_api.datamodels.dag_run import
DAGRunResponse
- from airflow.models import DagRun
-
- # TODO: Use the TaskAPI from within Triggerer to fetch full
context instead of sending this context
- # from the scheduler
-
- # Fetch the DagRun from the database again to avoid errors when
self.dagrun's relationship fields
- # are not in the current session.
- dagrun = session.get(DagRun, self.dagrun_id)
-
- return {
- "dag_run":
DAGRunResponse.model_validate(dagrun).model_dump(mode="json"),
- "deadline": {"id": str(self.id), "deadline_time":
self.deadline_time},
- }
-
- def callback_data_with_context():
- data = self.callback.data.copy()
- kwargs = dict(data.get("kwargs") or {})
- kwargs["context"] = get_simple_context()
- data["kwargs"] = kwargs
- return data
+ # Store only the ids needed to load the Dag run; the context is built
where the callback runs.
+ data = self.callback.data.copy()
+ data["dag_id"] = self.dagrun.dag_id
+ data["run_id"] = self.dagrun.run_id
+ data["deadline_id"] = str(self.id)
+ data["deadline_time"] = self.deadline_time.isoformat()
Review Comment:
This turns context["deadline"]["deadline_time"] from a datetime into a
string on both paths. Callbacks doing date math on it break, and {{
deadline.deadline_time | ds }} raises AttributeError and is passed unrendered.
Storing the datetime won't survive the workload JSON to remote workers, so I'd
parse it back to an aware datetime when the context is built, with a test on
the type
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]