vincbeck commented on code in PR #77546:
URL: https://github.com/apache/airflow/pull/77546#discussion_r4701177545


##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -1204,16 +1204,42 @@ def _build_schedulable_tis_query(
             # transient (via make_transient) before ExecuteTask.make() reads
             # ti.dag_run.created_dag_version.version_data to ship the bundle 
manifest matching
             # the run's pinned bundle_version. Lazy loads on transient objects 
silently return
-            # None instead of raising DetachedInstanceError. Scope the SELECT 
to version_data
-            # (the PK is auto-included) so we read two columns rather than the 
full row.
+            # None instead of raising DetachedInstanceError. Scope the SELECT 
to version_data and
+            # bundle_version, the columns ExecuteTask.make() reads (the PK is 
auto-included), to
+            # avoid a lazy load after the commit, which fails once the Dag is 
deleted.
             .options(
                 joinedload(TI.dag_run)
                 .selectinload(DagRun.created_dag_version)
-                .load_only(DagVersion.version_data)
+                .load_only(DagVersion.version_data, DagVersion.bundle_version)
             )
             .limit(max_tis)
         )
 
+    def _build_pre_assigning_executor_filter(self) -> ColumnElement[bool] | 
bool:

Review Comment:
   Done



##########
airflow-core/src/airflow/jobs/scheduler_job_runner.py:
##########
@@ -1338,17 +1352,39 @@ def _get_sentry_integration(executor: BaseExecutor) -> 
str:
                 return ""
             return sentry_integration
 
-        log_contexts = prepare_task_log_contexts(
-            [
-                ti
-                for ti in task_instances
-                if ti.dag_version_id and ti.dag_run.state not in 
State.finished_dr_states
-            ],
-            session=session,
-            dag_bag=self.scheduler_dag_bag,
-            filename_template=conf.get("logging", "log_filename_template"),
-        )
+        log_tis = [
+            ti
+            for ti in task_instances
+            if ti.dag_version_id and ti.dag_run.state not in 
State.finished_dr_states
+        ]
+        while True:
+            try:
+                log_contexts = prepare_task_log_contexts(
+                    log_tis,
+                    session=session,
+                    dag_bag=self.scheduler_dag_bag,
+                    filename_template=conf.get("logging", 
"log_filename_template"),
+                )
+                break
+            except KeyError:

Review Comment:
   Done



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