Skip to content

Commit fdf15ee

Browse files
authored
Fix: Reset the 'effective_from' attribute for migrated snapshots (#2313)
1 parent 5babece commit fdf15ee

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

sqlmesh/core/snapshot/definition.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@ def merge_intervals(self, other: t.Union[Snapshot, SnapshotIntervals]) -> None:
736736
previous_ids = {s.snapshot_id(self.name) for s in self.previous_versions}
737737
if self.identifier == other.identifier or (
738738
# Indirect Non-Breaking snapshots share the dev table with its previous version.
739-
self.is_indirect_non_breaking
739+
# The same applies to migrated snapshots.
740+
(self.is_indirect_non_breaking or self.migrated)
740741
and other.snapshot_id in previous_ids
741742
):
742743
for start, end in other.dev_intervals:

sqlmesh/core/state_sync/engine_adapter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,8 @@ def _visit(
10971097
logger.exception("Could not compute fingerprint for %s", snapshot.snapshot_id)
10981098
return
10991099

1100+
# Reset the effective_from date for the new snapshot to avoid unexpected backfills.
1101+
new_snapshot.effective_from = None
11001102
new_snapshot.previous_versions = snapshot.all_versions
11011103
new_snapshot.migrated = True
11021104
if not new_snapshot.temp_version:

tests/core/test_snapshot.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def test_add_interval(snapshot: Snapshot, make_snapshot):
198198
]
199199

200200

201-
def test_add_interval_dev(snapshot: Snapshot):
201+
def test_add_interval_dev(snapshot: Snapshot, make_snapshot):
202202
snapshot.version = "existing_version"
203203
snapshot.change_category = SnapshotChangeCategory.FORWARD_ONLY
204204

@@ -209,6 +209,18 @@ def test_add_interval_dev(snapshot: Snapshot):
209209
assert snapshot.intervals == [(to_timestamp("2020-01-01"), to_timestamp("2020-01-02"))]
210210
assert snapshot.dev_intervals == [(to_timestamp("2020-01-02"), to_timestamp("2020-01-03"))]
211211

212+
new_snapshot = make_snapshot(snapshot.model)
213+
new_snapshot.merge_intervals(snapshot)
214+
assert new_snapshot.intervals == [(to_timestamp("2020-01-01"), to_timestamp("2020-01-02"))]
215+
assert new_snapshot.dev_intervals == []
216+
217+
new_snapshot = make_snapshot(snapshot.model)
218+
new_snapshot.previous_versions = snapshot.all_versions
219+
new_snapshot.migrated = True
220+
new_snapshot.merge_intervals(snapshot)
221+
assert new_snapshot.intervals == [(to_timestamp("2020-01-01"), to_timestamp("2020-01-02"))]
222+
assert new_snapshot.dev_intervals == [(to_timestamp("2020-01-02"), to_timestamp("2020-01-03"))]
223+
212224

213225
def test_add_interval_partial(snapshot: Snapshot, make_snapshot):
214226
snapshot.add_interval("2023-01-01 00:00:00", "2023-01-01 23:59:59")

0 commit comments

Comments
 (0)