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



##########
File path: airflow/models/serialized_dag.py
##########
@@ -94,13 +97,26 @@ def write_dag(cls, dag: DAG, min_update_interval: 
Optional[int] = None, session=
                      (timezone.utcnow() - 
timedelta(seconds=min_update_interval)) < cls.last_updated))
             ).scalar():
                 return
-        log.debug("Writing DAG: %s to the DB", dag.dag_id)
-        session.merge(cls(dag))
+
+        log.debug("Checking if DAG (%s) is updated or same", dag.dag_id)
+        serialized_dag_from_db: SerializedDagModel = (
+            session
+            .query(cls)
+            .filter(cls.dag_id == dag.dag_id)
+            .one_or_none()
+        )

Review comment:
       Given we want to check that the SerializedDAG is changed or not, we want 
to access the DB rather than getting anything from the memory.
   
   I feel `.one_or_none` is better here but happy to hear your thoughts.




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