ephraimbuddy commented on code in PR #56422:
URL: https://github.com/apache/airflow/pull/56422#discussion_r2432334084


##########
airflow-core/src/airflow/models/serialized_dag.py:
##########
@@ -423,26 +423,29 @@ def write_dag(
             return False
 
         if dag_version and not dag_version.task_instances:
-            # This is for dynamic DAGs that the hashes changes often. We 
should update
-            # the serialized dag, the dag_version and the dag_code instead of 
a new version
-            # if the dag_version is not associated with any task instances
-            latest_ser_dag = cls.get(dag.dag_id, session=session)
-            if TYPE_CHECKING:
-                assert latest_ser_dag is not None
-            # Update the serialized DAG with the new_serialized_dag
-            latest_ser_dag._data = new_serialized_dag._data
-            latest_ser_dag._data_compressed = 
new_serialized_dag._data_compressed
-            latest_ser_dag.dag_hash = new_serialized_dag.dag_hash
-            session.merge(latest_ser_dag)
-            # The dag_version and dag_code may not have changed, still we 
should
-            # do the below actions:
-            # Update the latest dag version
-            dag_version.bundle_name = bundle_name
-            dag_version.bundle_version = bundle_version
-            session.merge(dag_version)
-            # Update the latest DagCode
-            DagCode.update_source_code(dag_id=dag.dag_id, fileloc=dag.fileloc, 
session=session)
-            return True
+            # This is for dynamic DAGs whose hashes change often. We should 
update
+            # the serialized DAG, the dag_version, and the dag_code instead of 
creating
+            # a new version if the dag_version has no associated task 
instances.
+
+            latest_ser_dag = dag_version.serialized_dag  # Use serialized_dag 
directly from dag_version
+
+            if latest_ser_dag:

Review Comment:
   If we have `dag_version`, then there must be a serialized_dag. We need to 
make sure that latest_ser_dag is never none. You should make sure that 
`serialized_dag` is loaded when `DagVersion.get_latest_version` is called. So 
also update that method



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to