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

 ##########
 File path: airflow/models/__init__.py
 ##########
 @@ -4012,17 +4088,55 @@ def create_dagrun(self,
             conf=conf,
             state=state
         )
+
+        dag_model = DagModel.get_dagmodel(self.dag_id)
+
+        tis = self.create_tis(execution_date)
+        edges = self.create_edges(-1)
+
+        last_run = dag_model.get_last_dagrun(include_externally_triggered=True)
+        if last_run is None:
+            same = False
+        else:
+            last_edges = DagEdge.fetch_edges_db(self.dag_id, last_run.graph_id)
+
+            # Compare edges from last run
+            same = True
+            if len(last_edges) != len(edges):
+                same = False
+            else:
+                e1 = set([(edge.from_task, edge.to_task) for edge in 
last_edges])
+                e2 = set([(edge.from_task, edge.to_task) for edge in edges])
+                if e1 != e2:
+                    same = False
+
+        if same:
+            # graph is not changed, keep last graph_id
+            graph_id = last_run.graph_id
+        elif last_run is None or last_run.graph_id is None:
+            # no graph known yet, beginning at 1
+            graph_id = 1
+        else:
+            # graph is changed
+            graph_id = last_run.graph_id + 1
+
+        for edge in edges:
+            edge.graph_id = graph_id
+
+        run.graph_id = graph_id
         session.add(run)
 
+        for ti in tis:
+            session.merge(ti)
+        if not same:
+            for edge in edges:
+                session.merge(edge)
 
 Review comment:
   After fixing this 37 I'm getting 89 more failing tests :(. Now already 
working on so going to do an iterative testing

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