Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to find end date for previous success TI #34528

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -1073,6 +1073,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 @@ -1113,6 +1114,7 @@ def f(
prev_execution_date,
prev_execution_date_success,
prev_start_date_success,
prev_end_date_success,
# other
**context,
):
Expand Down