Skip to content

Commit 6485230

Browse files
pr feedback
1 parent 21df382 commit 6485230

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
@@ -155,6 +155,7 @@ def __init__(
155155

156156
self._backfill_models = backfill_models
157157
self._end = end or default_end
158+
self._default_start = default_start
158159
self._apply = apply
159160
self._console = console or get_console()
160161
self._choices: t.Dict[SnapshotId, SnapshotChangeCategory] = {}
@@ -802,6 +803,25 @@ def _ensure_valid_date_range(self) -> None:
802803
f"Plan end date: '{time_like_to_str(end)}' cannot be in the future (execution time: '{time_like_to_str(self.execution_time)}')"
803804
)
804805

806+
# Validate model-specific start/end dates
807+
if (start := self.start or self._default_start) and (end := self.end):
808+
start_ts = to_datetime(start)
809+
end_ts = to_datetime(end)
810+
if start_ts > end_ts:
811+
models_to_check: t.Set[str] = (
812+
set(self._backfill_models or [])
813+
| set(self._context_diff.modified_snapshots.keys())
814+
| {s.name for s in self._context_diff.added}
815+
| set((self._end_override_per_model or {}).keys())
816+
)
817+
for model_name in models_to_check:
818+
if snapshot := self._model_fqn_to_snapshot.get(model_name):
819+
if snapshot.node.start is None or to_datetime(snapshot.node.start) > end_ts:
820+
raise PlanError(
821+
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"
822+
f"Set the `start` attribute in your project config model defaults to avoid this issue."
823+
)
824+
805825
def _ensure_no_broken_references(self) -> None:
806826
for snapshot in self._context_diff.snapshots.values():
807827
broken_references = {

tests/core/test_context.py

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

30603060
# 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
30613061
with pytest.raises(
3062-
SQLMeshError,
3062+
PlanError,
30633063
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",
30643064
):
30653065
context.plan("dev", execution_time="1999-01-05")

0 commit comments

Comments
 (0)