Skip to content

Commit ce2fdfb

Browse files
committed
PR feedback
1 parent 5b1b04d commit ce2fdfb

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

sqlmesh/core/context.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,14 @@
120120
from sqlmesh.utils import UniqueKeyDict, Verbosity
121121
from sqlmesh.utils.concurrency import concurrent_apply_to_values
122122
from sqlmesh.utils.dag import DAG
123-
from sqlmesh.utils.date import TimeLike, now_ds, to_timestamp, format_tz_datetime, now_timestamp
123+
from sqlmesh.utils.date import (
124+
TimeLike,
125+
now_ds,
126+
to_timestamp,
127+
format_tz_datetime,
128+
now_timestamp,
129+
now,
130+
)
124131
from sqlmesh.utils.errors import (
125132
CircuitBreakerError,
126133
ConfigError,
@@ -1517,7 +1524,7 @@ def plan_builder(
15171524
max_interval_end_per_model,
15181525
backfill_models,
15191526
modified_model_names,
1520-
execution_time,
1527+
execution_time or now(),
15211528
)
15221529

15231530
# Refresh snapshot intervals to ensure that they are up to date with values reflected in the max_interval_end_per_model.

sqlmesh/core/plan/builder.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def __init__(
139139
self._include_unmodified = include_unmodified
140140
self._restate_models = set(restate_models) if restate_models is not None else None
141141
self._effective_from = effective_from
142-
self._execution_time = execution_time
142+
self._execution_time = execution_time or now()
143143
self._backfill_models = backfill_models
144144
self._end = end or default_end
145145
self._apply = apply
@@ -176,20 +176,16 @@ def is_start_and_end_allowed(self) -> bool:
176176

177177
@property
178178
def start(self) -> t.Optional[TimeLike]:
179-
if self._start and self._execution_time:
179+
if self._start:
180180
return to_datetime(self._start, relative_base=to_datetime(self._execution_time))
181181
return self._start
182182

183183
@property
184184
def end(self) -> t.Optional[TimeLike]:
185-
if self._end and self._execution_time:
185+
if self._end:
186186
return to_datetime(self._end, relative_base=to_datetime(self._execution_time))
187187
return self._end
188188

189-
@property
190-
def execution_time(self) -> TimeLike:
191-
return self._execution_time or now()
192-
193189
def set_start(self, new_start: TimeLike) -> PlanBuilder:
194190
self._start = new_start
195191
self.override_start = True
@@ -274,7 +270,8 @@ def build(self) -> Plan:
274270
)
275271

276272
restatements = self._build_restatements(
277-
dag, earliest_interval_start(self._context_diff.snapshots.values(), self.execution_time)
273+
dag,
274+
earliest_interval_start(self._context_diff.snapshots.values(), self._execution_time),
278275
)
279276
models_to_backfill = self._build_models_to_backfill(dag, restatements)
280277

@@ -307,7 +304,7 @@ def build(self) -> Plan:
307304
selected_models_to_backfill=self._backfill_models,
308305
models_to_backfill=models_to_backfill,
309306
effective_from=self._effective_from,
310-
execution_time=self.execution_time,
307+
execution_time=self._execution_time,
311308
end_bounded=self._end_bounded,
312309
ensure_finalized_snapshots=self._ensure_finalized_snapshots,
313310
user_provided_flags=self._user_provided_flags,
@@ -764,9 +761,9 @@ def _ensure_valid_date_range(self) -> None:
764761
)
765762

766763
if end := self.end:
767-
if to_datetime(end) > to_datetime(self.execution_time):
764+
if to_datetime(end) > to_datetime(self._execution_time):
768765
raise PlanError(
769-
f"Plan end date: '{time_like_to_str(end)}' cannot be in the future (execution time: '{time_like_to_str(self.execution_time)}')"
766+
f"Plan end date: '{time_like_to_str(end)}' cannot be in the future (execution time: '{time_like_to_str(self._execution_time)}')"
770767
)
771768

772769
def _ensure_no_forward_only_revert(self) -> None:

sqlmesh/core/plan/definition.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ def start(self) -> TimeLike:
8383
def end(self) -> TimeLike:
8484
return self.provided_end or self.execution_time
8585

86-
@property
86+
@cached_property
8787
def execution_time(self) -> TimeLike:
88+
# note: property is cached so that it returns a consistent timestamp for now()
8889
return self.execution_time_ or now()
8990

9091
@property

0 commit comments

Comments
 (0)