Skip to content

Commit

Permalink
Use func.count to count rows (apache#23657)
Browse files Browse the repository at this point in the history
  • Loading branch information
pingzh committed May 12, 2022
1 parent 1a8f1ee commit 2111d73
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion airflow/models/trigger.py
Expand Up @@ -168,7 +168,7 @@ def assign_unassigned(cls, triggerer_id, capacity, session=None):
"""
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:
Expand Down
2 changes: 1 addition & 1 deletion airflow/utils/db.py
Expand Up @@ -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():
Expand Down

0 comments on commit 2111d73

Please sign in to comment.