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



##########
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(
+                TaskInstance.task_id == self.external_task_id,
             )
-        else:
-            # .count() is inefficient
-            count = (
-                session.query(func.count())
-                .filter(
-                    DR.dag_id == self.external_dag_id,
-                    DR.state.in_(states),  # pylint: disable=no-member
-                    DR.execution_date.in_(dttm_filter),
-                )
-                .scalar()
-            )
-        return count
 
-    def _handle_execution_date_fn(self, context):
+        # .count() is inefficient

Review comment:
       Misplaced comment, I think this needs to be above L207




----------------------------------------------------------------
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