3838)
3939from sqlmesh .utils import to_snake_case
4040from sqlmesh .core .state_sync import StateSync
41+ from sqlmesh .utils import CorrelationId
4142from sqlmesh .utils .concurrency import NodeExecutionFailedError
4243from sqlmesh .utils .errors import PlanError , SQLMeshError
4344from sqlmesh .utils .dag import DAG
@@ -71,7 +72,7 @@ def __init__(
7172 self ,
7273 state_sync : StateSync ,
7374 snapshot_evaluator : SnapshotEvaluator ,
74- create_scheduler : t .Callable [[t .Iterable [Snapshot ]], Scheduler ],
75+ create_scheduler : t .Callable [[t .Iterable [Snapshot ], SnapshotEvaluator ], Scheduler ],
7576 default_catalog : t .Optional [str ],
7677 console : t .Optional [Console ] = None ,
7778 ):
@@ -89,6 +90,7 @@ def evaluate(
8990 ) -> None :
9091 self ._circuit_breaker = circuit_breaker
9192
93+ self .set_correlation_id (CorrelationId .from_plan_id (plan .plan_id ))
9294 self .console .start_plan_evaluation (plan )
9395 analytics .collector .on_plan_apply_start (
9496 plan = plan ,
@@ -228,7 +230,7 @@ def visit_backfill_stage(self, stage: stages.BackfillStage, plan: EvaluatablePla
228230 self .console .log_success ("SKIP: No model batches to execute" )
229231 return
230232
231- scheduler = self .create_scheduler (stage .all_snapshots .values ())
233+ scheduler = self .create_scheduler (stage .all_snapshots .values (), self . snapshot_evaluator )
232234 errors , _ = scheduler .run_merged_intervals (
233235 merged_intervals = stage .snapshot_to_intervals ,
234236 deployability_index = stage .deployability_index ,
@@ -249,7 +251,7 @@ def visit_audit_only_run_stage(
249251 return
250252
251253 # If there are any snapshots to be audited, we'll reuse the scheduler's internals to audit them
252- scheduler = self .create_scheduler (audit_snapshots )
254+ scheduler = self .create_scheduler (audit_snapshots , self . snapshot_evaluator )
253255 completion_status = scheduler .audit (
254256 plan .environment ,
255257 plan .start ,
@@ -349,6 +351,13 @@ def visit_finalize_environment_stage(
349351 ) -> None :
350352 self .state_sync .finalize (plan .environment )
351353
354+ def set_correlation_id (self , correlation_id : CorrelationId ) -> None :
355+ for key , adapter in self .snapshot_evaluator .adapters .items ():
356+ if correlation_id != adapter .correlation_id :
357+ self .snapshot_evaluator .adapters [key ] = adapter .with_settings (
358+ correlation_id = correlation_id
359+ )
360+
352361 def _promote_snapshots (
353362 self ,
354363 plan : EvaluatablePlan ,
0 commit comments