Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlmesh/core/snapshot/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ def depends_on_past(self) -> bool:
An example of this can be an INCREMENTAL_BY_TIME_RANGE model that references previous records from itself.
2. Models that can only be restated from the beginning of history *and* their interval batches must be processed sequentially.
"""
return self.depends_on_self or self.full_history_restatement_only
return self.full_history_restatement_only or self.depends_on_self
Comment thread
mday-io marked this conversation as resolved.
Resolved

@property
def depends_on_self(self) -> bool:
Expand Down
25 changes: 25 additions & 0 deletions tests/core/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,31 @@ def test_get_removal_intervals_full_history_restatement_model(make_snapshot):
assert interval == (to_timestamp("2023-01-01"), execution_time)


def test_get_removal_interval_full_history_does_not_render_model(
make_snapshot: t.Callable[..., Snapshot], mocker: MockerFixture
):
# Full history restatement models are already known to depend on past intervals, so computing
# the removal interval must not render the model query (which may fail to hydrate user code).
model = SqlModel(
name="name",
kind=IncrementalUnmanagedKind(),
query=parse_one("SELECT 1"),
)
snapshot = make_snapshot(model)
snapshot.add_interval("2020-01-01", "2024-01-01")
# Drop the cached dependencies, as for a snapshot loaded from the state sync.
snapshot.model._full_depends_on = None

render_query = mocker.patch.object(SqlModel, "render_query", side_effect=ModuleNotFoundError)

execution_time = to_timestamp("2024-01-02")
interval = snapshot.get_removal_interval(
"2023-01-01", "2023-01-01", execution_time=execution_time
)
assert interval == (to_timestamp("2020-01-01"), execution_time)
render_query.assert_not_called()


def test_get_removal_intervals_warns_when_requested_range_automatically_widened(
make_snapshot: t.Callable[..., Snapshot], mocker: MockerFixture
):
Expand Down
Loading