You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2021/09/23 20:02:55 UTC
[airflow] branch main updated: Correctly select
``DagRun.execution_date`` from db (#18421)
This is an automated email from the ASF dual-hosted git repository.
kaxilnaik pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 1ef41be Correctly select ``DagRun.execution_date`` from db (#18421)
1ef41be is described below
commit 1ef41be175ad0c6d08be8be851561565fd716e89
Author: Tzu-ping Chung <tp...@astronomer.io>
AuthorDate: Fri Sep 24 04:02:35 2021 +0800
Correctly select ``DagRun.execution_date`` from db (#18421)
---
airflow/models/dag.py | 9 +++++----
airflow/www/views.py | 2 +-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/airflow/models/dag.py b/airflow/models/dag.py
index 17395ab..41f7b23 100644
--- a/airflow/models/dag.py
+++ b/airflow/models/dag.py
@@ -1180,7 +1180,7 @@ class DAG(LoggingMixin):
return dagruns
@provide_session
- def get_latest_execution_date(self, session=None):
+ def get_latest_execution_date(self, session: Session) -> Optional[datetime]:
"""Returns the latest date for which at least one dag run exists"""
return session.query(func.max(DagRun.execution_date)).filter(DagRun.dag_id == self.dag_id).scalar()
@@ -1269,8 +1269,8 @@ class DAG(LoggingMixin):
``base_date``, or more if there are manual task runs between the
requested period, which does not count toward ``num``.
"""
- min_date = (
- session.query(DagRun)
+ min_date: Optional[datetime] = (
+ session.query(DagRun.execution_date)
.filter(
DagRun.dag_id == self.dag_id,
DagRun.execution_date <= base_date,
@@ -1278,7 +1278,8 @@ class DAG(LoggingMixin):
)
.order_by(DagRun.execution_date.desc())
.offset(num)
- .first()
+ .limit(1)
+ .scalar()
)
if min_date is None:
min_date = timezone.utc_epoch()
diff --git a/airflow/www/views.py b/airflow/www/views.py
index b2c8712..919dc19 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -2523,7 +2523,7 @@ class Airflow(AirflowBaseView):
dag_model = DagModel.get_dagmodel(dag_id)
try:
- dag = current_app.dag_bag.get_dag(dag_id)
+ dag: Optional[DAG] = current_app.dag_bag.get_dag(dag_id)
except airflow.exceptions.SerializedDagNotFound:
dag = None