Skip to content

Commit 70e60ac

Browse files
authored
Fix: Don't remove dev intervals when restating in production environment (#4922)
1 parent 1ecfedf commit 70e60ac

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

sqlmesh/core/state_sync/db/interval.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,11 @@ def remove_intervals(
111111
snapshot_ids = ", ".join(str(s.snapshot_id) for s, _ in intervals_to_remove)
112112
logger.info("Removing interval for snapshots: %s", snapshot_ids)
113113

114-
for is_dev in (True, False):
115-
self.engine_adapter.insert_append(
116-
self.intervals_table,
117-
_intervals_to_df(intervals_to_remove, is_dev=is_dev, is_removed=True),
118-
columns_to_types=self._interval_columns_to_types,
119-
)
114+
self.engine_adapter.insert_append(
115+
self.intervals_table,
116+
_intervals_to_df(intervals_to_remove, is_dev=False, is_removed=True),
117+
columns_to_types=self._interval_columns_to_types,
118+
)
120119

121120
def get_snapshot_intervals(
122121
self, snapshots: t.Collection[SnapshotNameVersionLike]

tests/core/state_sync/test_state_sync.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,7 @@ def test_remove_interval(state_sync: EngineAdapterStateSync, make_snapshot: t.Ca
326326
remove_records_count = state_sync.engine_adapter.fetchone(
327327
"SELECT COUNT(*) FROM sqlmesh._intervals WHERE name = '\"a\"' AND version = 'a' AND is_removed"
328328
)[0] # type: ignore
329-
assert (
330-
remove_records_count == num_of_removals * 4
331-
) # (1 dev record + 1 prod record) * 2 snapshots
329+
assert remove_records_count == num_of_removals * 2 # 2 * snapshots
332330

333331
snapshots = state_sync.get_snapshots([snapshot_a, snapshot_b])
334332

@@ -1634,7 +1632,7 @@ def test_delete_expired_snapshots_cleanup_intervals_shared_dev_version(
16341632
(to_timestamp("2023-01-01"), to_timestamp("2023-01-04")),
16351633
]
16361634
assert stored_new_snapshot.dev_intervals == [
1637-
(to_timestamp("2023-01-04"), to_timestamp("2023-01-10")),
1635+
(to_timestamp("2023-01-04"), to_timestamp("2023-01-11")),
16381636
]
16391637

16401638
# Check old snapshot's intervals
@@ -1643,7 +1641,7 @@ def test_delete_expired_snapshots_cleanup_intervals_shared_dev_version(
16431641
(to_timestamp("2023-01-01"), to_timestamp("2023-01-04")),
16441642
]
16451643
assert stored_snapshot.dev_intervals == [
1646-
(to_timestamp("2023-01-04"), to_timestamp("2023-01-10")),
1644+
(to_timestamp("2023-01-04"), to_timestamp("2023-01-11")),
16471645
]
16481646

16491647
# Check all intervals
@@ -1665,7 +1663,7 @@ def test_delete_expired_snapshots_cleanup_intervals_shared_dev_version(
16651663
identifier=new_snapshot.identifier,
16661664
version=snapshot.version,
16671665
dev_version=new_snapshot.dev_version,
1668-
dev_intervals=[(to_timestamp("2023-01-08"), to_timestamp("2023-01-10"))],
1666+
dev_intervals=[(to_timestamp("2023-01-08"), to_timestamp("2023-01-11"))],
16691667
),
16701668
],
16711669
key=compare_snapshot_intervals,
@@ -1681,7 +1679,7 @@ def test_delete_expired_snapshots_cleanup_intervals_shared_dev_version(
16811679
(to_timestamp("2023-01-01"), to_timestamp("2023-01-04")),
16821680
]
16831681
assert stored_new_snapshot.dev_intervals == [
1684-
(to_timestamp("2023-01-04"), to_timestamp("2023-01-10")),
1682+
(to_timestamp("2023-01-04"), to_timestamp("2023-01-11")),
16851683
]
16861684

16871685
# Check all intervals
@@ -1709,7 +1707,7 @@ def test_delete_expired_snapshots_cleanup_intervals_shared_dev_version(
17091707
identifier=new_snapshot.identifier,
17101708
version=snapshot.version,
17111709
dev_version=new_snapshot.dev_version,
1712-
dev_intervals=[(to_timestamp("2023-01-08"), to_timestamp("2023-01-10"))],
1710+
dev_intervals=[(to_timestamp("2023-01-08"), to_timestamp("2023-01-11"))],
17131711
),
17141712
],
17151713
key=compare_snapshot_intervals,

0 commit comments

Comments
 (0)