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

Correctly handle None returns from Query.scalar() #16345

Merged
merged 1 commit into from Jun 15, 2021
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
6 changes: 3 additions & 3 deletions airflow/models/serialized_dag.py
Expand Up @@ -280,7 +280,7 @@ def get_last_updated_datetime(cls, dag_id: str, session: Session = None) -> Opti

@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
Expand All @@ -291,15 +291,15 @@ def get_max_last_updated_datetime(cls, session: Session = None) -> datetime:

@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.
:param dag_id: DAG ID
: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()
Expand Down
3 changes: 2 additions & 1 deletion airflow/www/views.py
Expand Up @@ -4093,7 +4093,8 @@ def list(self):
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()

Expand Down