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/06/15 19:23:45 UTC

[airflow] branch main updated: Correctly handle None returns from Query.scalar() (#16345)

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 147bcec  Correctly handle None returns from Query.scalar() (#16345)
147bcec is described below

commit 147bcecc4902793e0b913dfdad1bd799621971c7
Author: Tzu-ping Chung <tp...@astronomer.io>
AuthorDate: Wed Jun 16 03:23:32 2021 +0800

    Correctly handle None returns from Query.scalar() (#16345)
    
    This is possible when the query does not return a row, according to
    SQLAlchemy documentation. We can handle them to provide better errors in
    unexpected situations.
    
    Toward #8171, fix #16328.
---
 airflow/models/serialized_dag.py | 6 +++---
 airflow/www/views.py             | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/airflow/models/serialized_dag.py b/airflow/models/serialized_dag.py
index 2457e43..21db9f6 100644
--- a/airflow/models/serialized_dag.py
+++ b/airflow/models/serialized_dag.py
@@ -280,7 +280,7 @@ class SerializedDagModel(Base):
 
     @classmethod
     @provide_session
-    def get_max_last_updated_datetime(cls, session: Session = None) -> datetime:
+    def get_max_last_updated_datetime(cls, session: Session = None) -> Optional[datetime]:
         """
         Get the maximum date when any DAG was last updated in serialized_dag table
 
@@ -291,7 +291,7 @@ class SerializedDagModel(Base):
 
     @classmethod
     @provide_session
-    def get_latest_version_hash(cls, dag_id: str, session: Session = None) -> str:
+    def get_latest_version_hash(cls, dag_id: str, session: Session = None) -> Optional[str]:
         """
         Get the latest DAG version for a given DAG ID.
 
@@ -299,7 +299,7 @@ class SerializedDagModel(Base):
         :type dag_id: str
         :param session: ORM Session
         :type session: Session
-        :return: DAG Hash
+        :return: DAG Hash, or None if the DAG is not found
         :rtype: str | None
         """
         return session.query(cls.dag_hash).filter(cls.dag_id == dag_id).scalar()
diff --git a/airflow/www/views.py b/airflow/www/views.py
index 009bcac..a1e6172 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -4093,7 +4093,8 @@ class DagDependenciesView(AirflowBaseView):
         title = "DAG Dependencies"
 
         if timezone.utcnow() > self.last_refresh + self.refresh_interval:
-            if SerializedDagModel.get_max_last_updated_datetime() > self.last_refresh:
+            max_last_updated = SerializedDagModel.get_max_last_updated_datetime()
+            if max_last_updated is None or max_last_updated > self.last_refresh:
                 self._calculate_graph()
             self.last_refresh = timezone.utcnow()