XD-DENG commented on a change in pull request #4547: [AIRFLOW-2843] Add flag in 
ExternalTaskSensor to check if external DAG/task exists
URL: https://github.com/apache/airflow/pull/4547#discussion_r248673451
 
 

 ##########
 File path: airflow/sensors/external_task_sensor.py
 ##########
 @@ -103,17 +114,37 @@ def poke(self, context, session=None):
             '{self.external_task_id} on '
             '{} ... '.format(serialized_dttm_filter, **locals()))
 
-        if self.external_task_id:
-            TI = TaskInstance
+        DM = DagModel
+        TI = TaskInstance
+        DR = DagRun
+        if self.check_existence:
+            dag_to_wait = session.query(DM).filter(
+                DM.dag_id == self.external_dag_id
+            ).first()
+
+            if not dag_to_wait:
+                raise AirflowException('The external DAG '
+                                       '{} does not 
exist.'.format(self.external_dag_id))
+            else:
+                if not os.path.exists(dag_to_wait.fileloc):
+                    raise AirflowException('The external DAG '
+                                           '{} was 
deleted.'.format(self.external_dag_id))
 
+            if self.external_task_id:
+                refreshed_dag_info = 
DagBag(dag_to_wait.fileloc).get_dag(self.external_dag_id)
 
 Review comment:
   1. Purposely leave `include_examples` for `DagBag` to be default value 
`True`, since the `external_dag_id` may be example DAG.
   
   2. The exact file path is given to `DagBag`, so that it will only scan a 
single DAG file. This helps ensure no heavy overhead.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to