Skip to content

Commit 6897560

Browse files
committed
Fix: Delete associated records in the '_seeds' table when deleting a snapshot (#1896)
1 parent 28277ff commit 6897560

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

sqlmesh/core/state_sync/engine_adapter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ def delete_expired_environments(self) -> t.List[Environment]:
276276
def delete_snapshots(self, snapshot_ids: t.Iterable[SnapshotIdLike]) -> None:
277277
for where in self._snapshot_id_filter(snapshot_ids):
278278
self.engine_adapter.delete_from(self.snapshots_table, where=where)
279+
self.engine_adapter.delete_from(self.seeds_table, where=where)
279280

280281
def snapshots_exist(self, snapshot_ids: t.Iterable[SnapshotIdLike]) -> t.Set[SnapshotId]:
281282
return {

tests/core/test_state_sync.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,6 @@ def test_duplicates(state_sync: EngineAdapterStateSync, make_snapshot: t.Callabl
198198
)
199199

200200

201-
def test_delete_snapshots(state_sync: EngineAdapterStateSync, snapshots: t.List[Snapshot]) -> None:
202-
state_sync.push_snapshots(snapshots)
203-
snapshot_ids = [s.snapshot_id for s in snapshots]
204-
assert state_sync.get_snapshots(snapshot_ids)
205-
state_sync.delete_snapshots(snapshot_ids)
206-
assert not state_sync.get_snapshots(snapshot_ids)
207-
208-
209201
def test_snapshots_exists(state_sync: EngineAdapterStateSync, snapshots: t.List[Snapshot]) -> None:
210202
state_sync.push_snapshots(snapshots)
211203
snapshot_ids = {snapshot.snapshot_id for snapshot in snapshots}
@@ -1555,9 +1547,21 @@ def test_snapshot_batching(state_sync, mocker, make_snapshot):
15551547
)
15561548
)
15571549
calls = mock.delete_from.call_args_list
1558-
assert len(calls) == 2
1559-
assert calls[0][1] == {"where": parse_one("(name, identifier) in (('a', '1'), ('a', '2'))")}
1560-
assert calls[1][1] == {"where": parse_one("(name, identifier) in (('a', '3'))")}
1550+
assert mock.delete_from.call_args_list == [
1551+
call(
1552+
exp.to_table("sqlmesh._snapshots"),
1553+
where=parse_one("(name, identifier) in (('a', '1'), ('a', '2'))"),
1554+
),
1555+
call(
1556+
exp.to_table("sqlmesh._seeds"),
1557+
where=parse_one("(name, identifier) in (('a', '1'), ('a', '2'))"),
1558+
),
1559+
call(
1560+
exp.to_table("sqlmesh._snapshots"),
1561+
where=parse_one("(name, identifier) in (('a', '3'))"),
1562+
),
1563+
call(exp.to_table("sqlmesh._seeds"), where=parse_one("(name, identifier) in (('a', '3'))")),
1564+
]
15611565

15621566
mock.fetchall.side_effect = [
15631567
[

0 commit comments

Comments
 (0)