astahlman commented on a change in pull request #4396: [AIRFLOW-3585] - Add
edges to database
URL: https://github.com/apache/airflow/pull/4396#discussion_r257084944
##########
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):
Review comment:
I think this could be expressed more simply as:
```python
prev_edges = [(edge.from_task, edge.to_task)
for edge in last_edges]
current_edges = [(edge.from_task, edge.to_task)
for edge in edges])
is_dag_unchanged = len(current_edges) == len(prev_edges)
is_dag_unchanged &= set(current_edges) == set(prev_edges)
```
If these lists can contain duplicates (don't think they should?) you could
even drop the `len()` check.
----------------------------------------------------------------
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