Skip to content

Commit 09d91b1

Browse files
committed
do not cap backfills when no explicit start is set and default_pr_start=None and using implicit model selection
1 parent efa54fa commit 09d91b1

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

sqlmesh/core/plan/builder.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,12 @@ def __init__(
187187
self._start = start
188188
if not self._start and self._forward_only_preview_needed:
189189
self._preview_start = self._preview_start or default_start or yesterday_ds()
190-
# Only use the preview fallback as the plan start for implicit selection.
190+
# Keep the forward-only preview window separate from the plan start.
191+
# The plan start bounds regular backfills, so it should continue to
192+
# use the state-derived default start when one is available.
191193
# None means no explicit selection; an empty set intentionally backfills no models.
192194
if self._backfill_models is None:
193-
self._start = self._preview_start
195+
self._start = default_start or yesterday_ds()
194196

195197
if not self._start and self._non_forward_only_preview_needed:
196198
# Do not bind explicit non-preview backfills to the short preview range.

tests/core/test_plan.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,6 +2986,63 @@ def _make_forward_only_preview_context_diff(make_snapshot):
29862986
return context_diff, new_snapshot
29872987

29882988

2989+
def test_forward_only_preview_start_does_not_override_implicit_backfill_start(make_snapshot):
2990+
context_diff, new_snapshot = _make_forward_only_preview_context_diff(make_snapshot)
2991+
2992+
normal_old_snapshot = make_snapshot(
2993+
SqlModel(
2994+
name="normal",
2995+
query=parse_one("select 1, ds"),
2996+
dialect="duckdb",
2997+
kind=dict(name=ModelKindName.INCREMENTAL_BY_TIME_RANGE, time_column="ds"),
2998+
start="2025-01-01",
2999+
)
3000+
)
3001+
normal_old_snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
3002+
normal_new_snapshot = make_snapshot(
3003+
SqlModel(
3004+
name="normal",
3005+
query=parse_one("select 2, ds"),
3006+
dialect="duckdb",
3007+
kind=dict(name=ModelKindName.INCREMENTAL_BY_TIME_RANGE, time_column="ds"),
3008+
start="2025-01-01",
3009+
)
3010+
)
3011+
normal_new_snapshot.previous_versions = normal_old_snapshot.all_versions
3012+
3013+
context_diff.modified_snapshots[normal_new_snapshot.name] = (
3014+
normal_new_snapshot,
3015+
normal_old_snapshot,
3016+
)
3017+
context_diff.snapshots[normal_new_snapshot.snapshot_id] = normal_new_snapshot
3018+
context_diff.new_snapshots[normal_new_snapshot.snapshot_id] = normal_new_snapshot
3019+
3020+
plan = PlanBuilder(
3021+
context_diff,
3022+
default_start="2025-01-01",
3023+
end="2025-01-04",
3024+
preview_start="2025-01-03",
3025+
skip_backfill=False,
3026+
is_dev=True,
3027+
enable_preview=True,
3028+
).build()
3029+
3030+
assert plan.start == "2025-01-01"
3031+
assert plan.restatements == {
3032+
new_snapshot.snapshot_id: (
3033+
to_timestamp("2025-01-03"),
3034+
to_timestamp("2025-01-05"),
3035+
)
3036+
}
3037+
missing_intervals = {i.snapshot_id: i.intervals for i in plan.missing_intervals}
3038+
assert missing_intervals[normal_new_snapshot.snapshot_id] == [
3039+
(to_timestamp("2025-01-01"), to_timestamp("2025-01-02")),
3040+
(to_timestamp("2025-01-02"), to_timestamp("2025-01-03")),
3041+
(to_timestamp("2025-01-03"), to_timestamp("2025-01-04")),
3042+
(to_timestamp("2025-01-04"), to_timestamp("2025-01-05")),
3043+
]
3044+
3045+
29893046
def test_forward_only_preview_start_does_not_limit_regular_backfill(make_snapshot):
29903047
context_diff, preview_new_snapshot = _make_forward_only_preview_context_diff(make_snapshot)
29913048

0 commit comments

Comments
 (0)