This is an automated email from the ASF dual-hosted git repository.

ash pushed a commit to branch v2-1-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 777fd9b3a92b942f268cbb9869d62d2c9d2d9ed1
Author: Tzu-ping Chung <[email protected]>
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.
    
    (cherry picked from commit 147bcecc4902793e0b913dfdad1bd799621971c7)
---
 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 4e8ebc4..bba58ad 100644
--- a/airflow/models/serialized_dag.py
+++ b/airflow/models/serialized_dag.py
@@ -275,7 +275,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
 
@@ -286,7 +286,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.
 
@@ -294,7 +294,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 eadec6c..424892e 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -4023,7 +4023,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()
 

Reply via email to