You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/11/23 20:02:33 UTC

[GitHub] [airflow] turbaszek commented on a change in pull request #12574: Improve code quality of ExternalTaskSensor

turbaszek commented on a change in pull request #12574:
URL: https://github.com/apache/airflow/pull/12574#discussion_r528963335



##########
File path: airflow/sensors/external_task_sensor.py
##########
@@ -203,35 +204,21 @@ def get_count(self, dttm_filter, session, states):
         :type states: list
         :return: count of record against the filters
         """
-        TI = TaskInstance
-        DR = DagRun
+        qry = session.query(func.count()).filter(
+            DagRun.dag_id == self.external_dag_id,
+            DagRun.state.in_(states),  # pylint: disable=no-member
+            DagRun.execution_date.in_(dttm_filter),
+        )
 
         if self.external_task_id:
-            # .count() is inefficient
-            count = (
-                session.query(func.count())
-                .filter(
-                    TI.dag_id == self.external_dag_id,
-                    TI.task_id == self.external_task_id,
-                    TI.state.in_(states),  # pylint: disable=no-member
-                    TI.execution_date.in_(dttm_filter),
-                )
-                .scalar()
+            qry = qry.filter(

Review comment:
       Yes, my bad - I should read the code more thoughtfully! 🤯 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org