ffinfo commented on a change in pull request #4396: [AIRFLOW-3585] - Add edges 
to database
URL: https://github.com/apache/airflow/pull/4396#discussion_r259610682
 
 

 ##########
 File path: airflow/models/__init__.py
 ##########
 @@ -4019,17 +4073,50 @@ def create_dagrun(self,
             conf=conf,
             state=state
         )
+
+        dag_model = DagModel.get_dagmodel(self.dag_id)
+
+        tis = self.create_tis(execution_date)
+        # Setting graph_id temparary on -1, will set set later.
+        edges = self.create_edges(graph_id=-1)
+
+        last_dagrun = 
dag_model.get_last_dagrun(include_externally_triggered=True)
+        if last_dagrun is None:
+            is_dag_unchanged = False
+        else:
+            last_edges = DagEdge.fetch_edges(self.dag_id, last_dagrun.graph_id)
+
+            # Compare edges from last run
+            prev_edges = [(edge.task_from, edge.task_to) for edge in 
last_edges]
+            current_edges = [(edge.task_from, edge.task_to) for edge in edges]
+            is_dag_unchanged = len(current_edges) == len(prev_edges)
+            is_dag_unchanged &= set(current_edges) == set(prev_edges)
+
+        if is_dag_unchanged:
+            # graph is not changed, keep last graph_id
+            graph_id = last_dagrun.graph_id
+        elif last_dagrun is None or last_dagrun.graph_id is None:
+            # no graph known yet, beginning at 1
+            graph_id = 1
+        else:
+            # graph is changed
+            graph_id = last_dagrun.graph_id + 1
 
 Review comment:
   please look at this for the implementation: 
   
https://github.com/apache/airflow/pull/4396/commits/1469ae913f88eafd5e8b5dc00d7ff0fd77a9399f

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


With regards,
Apache Git Services

Reply via email to