XD-DENG commented on a change in pull request #12574:
URL: https://github.com/apache/airflow/pull/12574#discussion_r528953959



##########
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:
       I may have missed or mis-understood something: the original code is 
filtering against `TaskInstance` and `DagRun` separately in different 
conditions. But this new version is filtering against `DagRun` or 
`TaskInstance` PLUS `DagRun`.
   
   But I'm simply comparing the lines, so as I said above, possibly I 
misunderstood something.




----------------------------------------------------------------
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:
[email protected]


Reply via email to