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

uranusjr 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 2111d73a92 Use func.count to count rows (#23657)
2111d73a92 is described below

commit 2111d73a9277c8e036279f2cc59f146270ef8e5b
Author: Ping Zhang <[email protected]>
AuthorDate: Thu May 12 14:49:06 2022 -0700

    Use func.count to count rows (#23657)
---
 airflow/models/trigger.py | 2 +-
 airflow/utils/db.py       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/airflow/models/trigger.py b/airflow/models/trigger.py
index c1ccdd4964..24e62789b5 100644
--- a/airflow/models/trigger.py
+++ b/airflow/models/trigger.py
@@ -168,7 +168,7 @@ class Trigger(Base):
         """
         from airflow.jobs.base_job import BaseJob  # To avoid circular import
 
-        count = session.query(cls.id).filter(cls.triggerer_id == 
triggerer_id).count()
+        count = session.query(func.count(cls.id)).filter(cls.triggerer_id == 
triggerer_id).scalar()
         capacity -= count
 
         if capacity <= 0:
diff --git a/airflow/utils/db.py b/airflow/utils/db.py
index e624650dae..e64d8ba672 100644
--- a/airflow/utils/db.py
+++ b/airflow/utils/db.py
@@ -984,7 +984,7 @@ def check_run_id_null(session: Session) -> Iterable[str]:
         dagrun_table.c.run_id.is_(None),
         dagrun_table.c.execution_date.is_(None),
     )
-    invalid_dagrun_count = 
session.query(dagrun_table.c.id).filter(invalid_dagrun_filter).count()
+    invalid_dagrun_count = 
session.query(func.count(dagrun_table.c.id)).filter(invalid_dagrun_filter).scalar()
     if invalid_dagrun_count > 0:
         dagrun_dangling_table_name = 
_format_airflow_moved_table_name(dagrun_table.name, '2.2', 'dangling')
         if dagrun_dangling_table_name in 
inspect(session.get_bind()).get_table_names():

Reply via email to