Skip to content

Commit b101b0b

Browse files
authored
Fix: Don't expand start for full-history-restatement-only snapshots when previewing forward-only changes (#2739)
1 parent 0d86edc commit b101b0b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

sqlmesh/core/plan/builder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def is_restateable_snapshot(snapshot: Snapshot) -> bool:
314314

315315
restatements: t.Dict[SnapshotId, Interval] = {}
316316
forward_only_preview_needed = self._forward_only_preview_needed
317+
is_preview = False
317318
if not restate_models and forward_only_preview_needed:
318319
# Add model names for new forward-only snapshots to the restatement list
319320
# in order to compute previews.
@@ -322,6 +323,7 @@ def is_restateable_snapshot(snapshot: Snapshot) -> bool:
322323
for s in self._context_diff.new_snapshots.values()
323324
if s.is_materialized and (self._forward_only or s.model.forward_only)
324325
}
326+
is_preview = True
325327

326328
if not restate_models:
327329
return {}
@@ -358,6 +360,7 @@ def is_restateable_snapshot(snapshot: Snapshot) -> bool:
358360
self._end or now(),
359361
self._execution_time,
360362
strict=False,
363+
is_preview=is_preview,
361364
)
362365
# Since we are traversing the graph in topological order and the largest interval range is pushed down
363366
# the graph we just have to check our immediate parents in the graph and not the whole upstream graph.

sqlmesh/core/snapshot/definition.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,21 @@ def get_removal_interval(
675675
execution_time: t.Optional[TimeLike] = None,
676676
*,
677677
strict: bool = True,
678+
is_preview: bool = False,
678679
) -> Interval:
680+
"""Get the interval that should be removed from the snapshot.
681+
682+
Args:
683+
start: The start date/time of the interval to remove.
684+
end: The end date/time of the interval to removed.
685+
execution_time: The time the interval is being removed.
686+
strict: Whether to fail when the inclusive start is the same as the exclusive end.
687+
is_preview: Whether the interval needs to be removed for a preview of forward-only changes.
688+
When previewing, we are not actually restating a model, but removing an interval to trigger
689+
a run.
690+
"""
679691
end = execution_time or now() if self.depends_on_past else end
680-
if self.full_history_restatement_only and self.intervals:
692+
if not is_preview and self.full_history_restatement_only and self.intervals:
681693
start = self.intervals[0][0]
682694
return self.inclusive_exclusive(start, end, strict)
683695

0 commit comments

Comments
 (0)