kaxil commented on code in PR #54362:
URL: https://github.com/apache/airflow/pull/54362#discussion_r2267504786


##########
airflow-core/src/airflow/models/dagbag.py:
##########
@@ -752,7 +754,14 @@ def _version_from_dag_run(dag_run, session):
             if dag_version:
                 return dag_version
 
-        return dag_run.created_dag_version
+        # Check if created_dag_version relationship is already loaded to avoid 
DetachedInstanceError
+        info = inspect(dag_run)
+        if info.attrs.created_dag_version.loaded_value is not NO_VALUE:
+            # Relationship is already loaded, safe to access
+            return dag_run.created_dag_version
+
+        # Relationship not loaded, fetch it explicitly from current session
+        return session.get(DagVersion, dag_run.created_dag_version_id)

Review Comment:
   Let's get this issue unblocked and Ephraim & Daniel will decide on the 
longer term solution i.e. if we want to eagerly load the relationship or not



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