Skip to content

Commit eea85fc

Browse files
committed
more test fixes
Signed-off-by: Jesse Hodges <hodges.jesse@gmail.com>
1 parent 17aa1fd commit eea85fc

2 files changed

Lines changed: 7 additions & 134 deletions

File tree

sqlmesh/core/plan/builder.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,16 @@ def __init__(
188188
self._start = start
189189
if not self._start and self._forward_only_preview_needed:
190190
self._preview_start = self._preview_start or default_start or yesterday_ds()
191-
# Keep the forward-only preview window separate from the plan start.
192-
# The plan start bounds regular backfills, so it should continue to
193-
# use the state-derived default start when one is available.
194-
# None means no explicit selection; an empty set intentionally backfills no models.
195-
if self._backfill_models is None:
191+
# If a separate preview start was provided, don't let it shorten the
192+
# plan start for regular backfills. Fallback preview starts preserve
193+
# the previous preview behavior of using default_start or yesterday.
194+
if self._preview_start_provided and not self._skip_backfill:
196195
self._start = default_start or yesterday_ds()
196+
else:
197+
self._start = self._preview_start
197198

198199
if not self._start and self._non_forward_only_preview_needed:
199-
# Do not bind explicit non-preview backfills to the short preview range.
200-
if self._backfill_models is None:
201-
self._start = default_start or yesterday_ds()
200+
self._start = default_start or yesterday_ds()
202201

203202
self._plan_id: str = random_id()
204203
self._model_fqn_to_snapshot = {s.name: s for s in self._context_diff.snapshots.values()}

tests/core/test_plan.py

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,132 +3077,6 @@ def test_forward_only_preview_start_follows_implicit_plan_start_updates(make_sna
30773077
}
30783078

30793079

3080-
def test_forward_only_preview_start_does_not_limit_regular_backfill(make_snapshot):
3081-
context_diff, preview_new_snapshot = _make_forward_only_preview_context_diff(make_snapshot)
3082-
3083-
normal_old_snapshot = make_snapshot(
3084-
SqlModel(
3085-
name="normal",
3086-
query=parse_one("select 1, ds"),
3087-
dialect="duckdb",
3088-
kind=dict(name=ModelKindName.INCREMENTAL_BY_TIME_RANGE, time_column="ds"),
3089-
start="2025-01-01",
3090-
)
3091-
)
3092-
normal_old_snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
3093-
normal_new_snapshot = make_snapshot(
3094-
SqlModel(
3095-
name="normal",
3096-
query=parse_one("select 2, ds"),
3097-
dialect="duckdb",
3098-
kind=dict(name=ModelKindName.INCREMENTAL_BY_TIME_RANGE, time_column="ds"),
3099-
start="2025-01-01",
3100-
)
3101-
)
3102-
normal_new_snapshot.previous_versions = normal_old_snapshot.all_versions
3103-
3104-
context_diff.modified_snapshots[normal_new_snapshot.name] = (
3105-
normal_new_snapshot,
3106-
normal_old_snapshot,
3107-
)
3108-
context_diff.snapshots[normal_new_snapshot.snapshot_id] = normal_new_snapshot
3109-
context_diff.new_snapshots[normal_new_snapshot.snapshot_id] = normal_new_snapshot
3110-
3111-
plan = PlanBuilder(
3112-
context_diff,
3113-
default_start="2025-01-02",
3114-
end="2025-01-03",
3115-
preview_min_intervals=1,
3116-
backfill_models={normal_new_snapshot.name, preview_new_snapshot.name},
3117-
is_dev=True,
3118-
enable_preview=True,
3119-
).build()
3120-
3121-
missing_intervals = {i.snapshot_id: i.intervals for i in plan.missing_intervals}
3122-
3123-
assert plan.provided_start is None
3124-
assert missing_intervals == {
3125-
normal_new_snapshot.snapshot_id: [
3126-
(to_timestamp("2025-01-01"), to_timestamp("2025-01-02")),
3127-
(to_timestamp("2025-01-02"), to_timestamp("2025-01-03")),
3128-
(to_timestamp("2025-01-03"), to_timestamp("2025-01-04")),
3129-
],
3130-
preview_new_snapshot.snapshot_id: [
3131-
(to_timestamp("2025-01-02"), to_timestamp("2025-01-03")),
3132-
(to_timestamp("2025-01-03"), to_timestamp("2025-01-04")),
3133-
],
3134-
}
3135-
3136-
3137-
def test_non_forward_only_preview_start_does_not_limit_explicit_backfill(make_snapshot):
3138-
old_snapshot = make_snapshot(
3139-
SqlModel(
3140-
name="a",
3141-
query=parse_one("select 1, ds"),
3142-
dialect="duckdb",
3143-
kind=IncrementalByTimeRangeKind(
3144-
time_column="ds",
3145-
auto_restatement_cron="@daily",
3146-
),
3147-
start="2025-01-01",
3148-
)
3149-
)
3150-
old_snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
3151-
new_snapshot = make_snapshot(
3152-
SqlModel(
3153-
name="a",
3154-
query=parse_one("select 2, ds"),
3155-
dialect="duckdb",
3156-
kind=IncrementalByTimeRangeKind(
3157-
time_column="ds",
3158-
auto_restatement_cron="@daily",
3159-
),
3160-
start="2025-01-01",
3161-
)
3162-
)
3163-
new_snapshot.previous_versions = old_snapshot.all_versions
3164-
3165-
context_diff = ContextDiff(
3166-
environment="test_environment",
3167-
is_new_environment=True,
3168-
is_unfinalized_environment=False,
3169-
normalize_environment_name=True,
3170-
create_from="prod",
3171-
create_from_env_exists=True,
3172-
added=set(),
3173-
removed_snapshots={},
3174-
snapshots={new_snapshot.snapshot_id: new_snapshot},
3175-
new_snapshots={new_snapshot.snapshot_id: new_snapshot},
3176-
modified_snapshots={old_snapshot.name: (new_snapshot, old_snapshot)},
3177-
previous_plan_id=None,
3178-
previously_promoted_snapshot_ids=set(),
3179-
previous_finalized_snapshots=None,
3180-
previous_gateway_managed_virtual_layer=False,
3181-
gateway_managed_virtual_layer=False,
3182-
environment_statements=[],
3183-
)
3184-
3185-
plan = PlanBuilder(
3186-
context_diff,
3187-
default_start="2025-01-02",
3188-
end="2025-01-03",
3189-
backfill_models={new_snapshot.name},
3190-
is_dev=True,
3191-
).build()
3192-
3193-
assert plan.provided_start is None
3194-
assert plan.missing_intervals == [
3195-
SnapshotIntervals(
3196-
snapshot_id=new_snapshot.snapshot_id,
3197-
intervals=[
3198-
(to_timestamp("2025-01-01"), to_timestamp("2025-01-02")),
3199-
(to_timestamp("2025-01-02"), to_timestamp("2025-01-03")),
3200-
(to_timestamp("2025-01-03"), to_timestamp("2025-01-04")),
3201-
],
3202-
)
3203-
]
3204-
3205-
32063080
@time_machine.travel("2026-06-02 00:00:00 UTC")
32073081
def test_forward_only_preview_uses_preview_start(make_snapshot):
32083082
context_diff, new_snapshot = _make_forward_only_preview_context_diff(make_snapshot)

0 commit comments

Comments
 (0)