seanghaeli commented on code in PR #66608:
URL: https://github.com/apache/airflow/pull/66608#discussion_r3314156245
##########
task-sdk/src/airflow/sdk/execution_time/callback_supervisor.py:
##########
@@ -318,11 +334,68 @@ def _configure_logging(log_path: str) ->
tuple[FilteringBoundLogger, BinaryIO]:
return logger, log_file_descriptor
+def _fetch_and_build_context(
+ comms,
+ dag_id: str,
+ run_id: str,
+ _log,
+) -> dict | None:
+ """
+ Fetch DagRun via SUPERVISOR_COMMS and build a standard context dict.
+
+ Called inside the forked subprocess when DagRun identifiers are available.
+ Returns a context dict with dag_run, run_id, logical_date, ds, ts, etc.
+ Task-specific fields are absent since callbacks are not tied to a task.
+ """
+ try:
+ response = comms.send(GetDagRun(dag_id=dag_id, run_id=run_id))
+ if not isinstance(response, DagRunResult):
+ _log.warning(
+ "Unexpected response when fetching DagRun for callback
context",
+ response_type=type(response).__name__,
+ )
+ return None
+
+ context: dict = {"dag_run": response}
+
+ if response.logical_date:
+ logical_date = response.logical_date
+ ds = logical_date.strftime("%Y-%m-%d")
+ ts = logical_date.isoformat()
+ context.update(
+ {
+ "logical_date": logical_date,
+ "run_id": response.run_id,
+ "ds": ds,
+ "ds_nodash": ds.replace("-", ""),
+ "ts": ts,
+ "ts_nodash": logical_date.strftime("%Y%m%dT%H%M%S"),
+ "ts_nodash_with_tz": ts.replace("-", "").replace(":", ""),
+ "data_interval_start": response.data_interval_start,
Review Comment:
Noted. added.
--
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]