Skip to content

Commit

Permalink
prev_end_date_success method access (#34528)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bowrna committed Nov 3, 2023
1 parent 2bcd450 commit 61a9ab7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ def get_prev_start_date_success() -> pendulum.DateTime | None:
return None
return timezone.coerce_datetime(dagrun.start_date)

def get_prev_end_date_success() -> pendulum.DateTime | None:
dagrun = _get_previous_dagrun_success()
if dagrun is None:
return None
return timezone.coerce_datetime(dagrun.end_date)

@cache
def get_yesterday_ds() -> str:
return (logical_date - timedelta(1)).strftime("%Y-%m-%d")
Expand Down Expand Up @@ -729,6 +735,7 @@ def get_triggering_events() -> dict[str, list[DatasetEvent]]:
session=session,
),
"prev_start_date_success": get_prev_start_date_success(),
"prev_end_date_success": get_prev_end_date_success(),
"run_id": task_instance.run_id,
"task": task,
"task_instance": task_instance,
Expand Down
1 change: 1 addition & 0 deletions airflow/operators/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ class _BasePythonVirtualenvOperator(PythonOperator, metaclass=ABCMeta):
"prev_execution_date",
"prev_execution_date_success",
"prev_start_date_success",
"prev_end_date_success",
}
AIRFLOW_SERIALIZABLE_CONTEXT_KEYS = {
"macros",
Expand Down
1 change: 1 addition & 0 deletions airflow/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"prev_execution_date",
"prev_execution_date_success",
"prev_start_date_success",
"prev_end_date_success",
"run_id",
"task",
"task_instance",
Expand Down
1 change: 1 addition & 0 deletions airflow/utils/context.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Context(TypedDict, total=False):
prev_execution_date: DateTime | None
prev_execution_date_success: DateTime | None
prev_start_date_success: DateTime | None
prev_end_date_success: DateTime | None
reason: str | None
run_id: str
task: BaseOperator
Expand Down
2 changes: 2 additions & 0 deletions tests/operators/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@ def f(
prev_execution_date,
prev_execution_date_success,
prev_start_date_success,
prev_end_date_success,
# airflow-specific
macros,
conf,
Expand Down Expand Up @@ -1141,6 +1142,7 @@ def f(
prev_execution_date,
prev_execution_date_success,
prev_start_date_success,
prev_end_date_success,
# other
**context,
):
Expand Down

0 comments on commit 61a9ab7

Please sign in to comment.