Skip to content

Commit feb9686

Browse files
authored
chore: make it so duplicate snapshot push doesn't raise because this … (#3323)
1 parent 80d6a6d commit feb9686

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

sqlmesh/core/state_sync/engine_adapter.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,14 @@ def push_snapshots(self, snapshots: t.Iterable[Snapshot]) -> None:
208208
existing = self.snapshots_exist(snapshots_by_id)
209209

210210
if existing:
211-
raise SQLMeshError(f"Snapshots {existing} already exists.")
211+
logger.error(
212+
"Snapshots %s already exists. This could be due to a concurrent plan or a hash collision. If this is a hash collision, add a stamp to your model.",
213+
str(existing),
214+
)
215+
216+
for sid in tuple(snapshots_by_id):
217+
if sid in existing:
218+
snapshots_by_id.pop(sid)
212219

213220
snapshots = snapshots_by_id.values()
214221

tests/core/test_state_sync.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
import re
34
import typing as t
45
from unittest.mock import call, patch
@@ -141,17 +142,12 @@ def test_push_snapshots(
141142
snapshot_b.snapshot_id: snapshot_b,
142143
}
143144

144-
with pytest.raises(
145-
SQLMeshError,
146-
match=r".*already exists.*",
147-
):
145+
logger = logging.getLogger("sqlmesh.core.state_sync.engine_adapter")
146+
with patch.object(logger, "error") as mock_logger:
148147
state_sync.push_snapshots([snapshot_a])
149-
150-
with pytest.raises(
151-
SQLMeshError,
152-
match=r".*already exists.*",
153-
):
148+
assert str({snapshot_a.snapshot_id}) == mock_logger.call_args[0][1]
154149
state_sync.push_snapshots([snapshot_a, snapshot_b])
150+
assert str({snapshot_a.snapshot_id, snapshot_b.snapshot_id}) == mock_logger.call_args[0][1]
155151

156152
# test serialization
157153
state_sync.push_snapshots(

0 commit comments

Comments
 (0)