Skip to content

Commit d93ca2b

Browse files
pr feedback
1 parent 94ce8b8 commit d93ca2b

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

sqlmesh/core/context.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,28 +1603,6 @@ def plan_builder(
16031603
execution_time or now(),
16041604
)
16051605

1606-
# Validate that the start is not greater than the end date / time
1607-
effective_start = start or default_start
1608-
effective_end = end or default_end
1609-
if effective_start is not None and effective_end is not None:
1610-
start_ts = to_timestamp(effective_start)
1611-
end_ts = to_timestamp(effective_end)
1612-
if start_ts > end_ts:
1613-
for model_name in (
1614-
set(backfill_models or {})
1615-
| set(modified_model_names)
1616-
| set(max_interval_end_per_model)
1617-
):
1618-
if snapshot := snapshots.get(model_name):
1619-
if (
1620-
snapshot.node.start is None
1621-
or to_timestamp(snapshot.node.start) > end_ts
1622-
):
1623-
raise SQLMeshError(
1624-
f"Model '{model_name}': Start date / time ({to_datetime(start_ts)}) can't be greater than end date / time ({to_datetime(end_ts)}).\n"
1625-
f"Set the `start` attribute in your project config model defaults to avoid this issue."
1626-
)
1627-
16281606
# Refresh snapshot intervals to ensure that they are up to date with values reflected in the max_interval_end_per_model.
16291607
self.state_sync.refresh_snapshot_intervals(context_diff.snapshots.values())
16301608

sqlmesh/core/plan/builder.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def __init__(
154154

155155
self._backfill_models = backfill_models
156156
self._end = end or default_end
157+
self._default_start = default_start
157158
self._apply = apply
158159
self._console = console or get_console()
159160
self._choices: t.Dict[SnapshotId, SnapshotChangeCategory] = {}
@@ -797,6 +798,25 @@ def _ensure_valid_date_range(self) -> None:
797798
f"Plan end date: '{time_like_to_str(end)}' cannot be in the future (execution time: '{time_like_to_str(self.execution_time)}')"
798799
)
799800

801+
# Validate model-specific start/end dates
802+
if (start := self.start or self._default_start) and (end := self.end):
803+
start_ts = to_datetime(start)
804+
end_ts = to_datetime(end)
805+
if start_ts > end_ts:
806+
models_to_check: t.Set[str] = (
807+
set(self._backfill_models or [])
808+
| set(self._context_diff.modified_snapshots.keys())
809+
| {s.name for s in self._context_diff.added}
810+
| set((self._end_override_per_model or {}).keys())
811+
)
812+
for model_name in models_to_check:
813+
if snapshot := self._model_fqn_to_snapshot.get(model_name):
814+
if snapshot.node.start is None or to_datetime(snapshot.node.start) > end_ts:
815+
raise PlanError(
816+
f"Model '{model_name}': Start date / time '({time_like_to_str(start_ts)})' can't be greater than end date / time '({time_like_to_str(end_ts)})'.\n"
817+
f"Set the `start` attribute in your project config model defaults to avoid this issue."
818+
)
819+
800820
def _ensure_no_forward_only_revert(self) -> None:
801821
"""Ensures that a previously superseded breaking / non-breaking snapshot is not being
802822
used again to replace an existing forward-only snapshot with the same version.

tests/core/test_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3054,7 +3054,7 @@ def test_plan_no_start_configured():
30543054

30553055
# This should raise an error because the model has no start configured and the end time is less than the start time which will be calculated from the intervals
30563056
with pytest.raises(
3057-
SQLMeshError,
3057+
PlanError,
30583058
match=r"Model '.*xvg.*': Start date / time .* can't be greater than end date / time .*\.\nSet the `start` attribute in your project config model defaults to avoid this issue",
30593059
):
30603060
context.plan("dev", execution_time="1999-01-05")

0 commit comments

Comments
 (0)