dstandish commented on code in PR #54362:
URL: https://github.com/apache/airflow/pull/54362#discussion_r2267493405
##########
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:
this `return dag_run.created_dag_version` already is using the relationship
isn't it? but maybe you mean to suggest you make it eager load the object?
--
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]