Skip to content

Commit 32fd88a

Browse files
fix(plan): pass plan snapshots and deployability index to audit-only stage
Signed-off-by: Sruthi <codewithsruthi@users.noreply.github.com>
1 parent 1f96a72 commit 32fd88a

6 files changed

Lines changed: 829 additions & 4 deletions

File tree

‎sqlmesh/core/plan/evaluator.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,33 @@ def visit_audit_only_run_stage(
273273
if not audit_snapshots:
274274
return
275275

276+
# Copy snapshots (and their interval lists) so scheduler.audit's state refresh cannot
277+
# mutate shared Snapshot objects held by subsequent stages or CachingStateSync.
278+
snapshots = [
279+
s.copy(
280+
update={
281+
"intervals": s.intervals.copy(),
282+
"dev_intervals": s.dev_intervals.copy(),
283+
"pending_restatement_intervals": s.pending_restatement_intervals.copy(),
284+
}
285+
)
286+
for s in stage.all_snapshots.values()
287+
]
288+
276289
# If there are any snapshots to be audited, we'll reuse the scheduler's internals to audit them
277-
scheduler = self.create_scheduler(audit_snapshots, self.snapshot_evaluator)
290+
scheduler = self.create_scheduler(snapshots, self.snapshot_evaluator)
278291
completion_status = scheduler.audit(
279292
plan.environment,
280293
plan.start,
281294
plan.end,
282295
execution_time=plan.execution_time,
283296
end_bounded=plan.end_bounded,
297+
ignore_cron=plan.ignore_cron,
284298
start_override_per_model=plan.start_override_per_model,
285299
end_override_per_model=plan.end_override_per_model,
300+
selected_snapshots={s.name for s in audit_snapshots},
301+
deployability_index=stage.deployability_index,
302+
circuit_breaker=self._circuit_breaker,
286303
)
287304

288305
if completion_status.is_failure:

‎sqlmesh/core/plan/stages.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ class AuditOnlyRunStage:
9292
9393
Args:
9494
snapshots: Snapshots to run audits for.
95+
all_snapshots: All snapshots in the plan by name.
96+
deployability_index: Deployability index for this stage.
9597
"""
9698

9799
snapshots: t.List[Snapshot]
100+
all_snapshots: t.Dict[str, Snapshot]
101+
deployability_index: DeployabilityIndex
98102

99103

100104
@dataclass
@@ -346,7 +350,13 @@ def build(self, plan: EvaluatablePlan) -> t.List[PlanStage]:
346350

347351
audit_only_snapshots = self._get_audit_only_snapshots(new_snapshots)
348352
if audit_only_snapshots:
349-
stages.append(AuditOnlyRunStage(snapshots=list(audit_only_snapshots.values())))
353+
stages.append(
354+
AuditOnlyRunStage(
355+
snapshots=list(audit_only_snapshots.values()),
356+
all_snapshots=snapshots_by_name,
357+
deployability_index=deployability_index,
358+
)
359+
)
350360

351361
if missing_intervals_before_promote:
352362
stages.append(

‎sqlmesh/core/scheduler.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ def audit(
314314
# by _run_or_audit as "missing intervals" to reuse the rest of it's logic
315315
remove_intervals = {}
316316
for snapshot in self.snapshots.values():
317+
if not snapshot.evaluatable or (
318+
selected_snapshots is not None and snapshot.name not in selected_snapshots
319+
):
320+
continue
317321
removal_intervals = snapshot.get_removal_interval(
318322
start, end, execution_time, is_preview=True
319323
)
@@ -859,8 +863,9 @@ def _run_or_audit(
859863
execution_time = execution_time or now_timestamp()
860864

861865
self.state_sync.refresh_snapshot_intervals(self.snapshots.values())
862-
for s_id, interval in (remove_intervals or {}).items():
863-
self.snapshots[s_id].remove_interval(interval)
866+
if not audit_only:
867+
for s_id, interval in (remove_intervals or {}).items():
868+
self.snapshots[s_id].remove_interval(interval)
864869

865870
all_auto_restatement_triggers: t.Dict[SnapshotId, t.List[SnapshotId]] = {}
866871
if auto_restatement_enabled:

0 commit comments

Comments
 (0)