ephraimbuddy commented on code in PR #54362:
URL: https://github.com/apache/airflow/pull/54362#discussion_r2267471338
##########
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:
How about we set dag_run - dag_version relationship itself to load this
info. I suggested this when @dstandish was working on this. dag_version is a
lightweight table. Loading it when querying dag_run would have a very minimal
impact.
--
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]