Skip to content

Commit c143dac

Browse files
authored
Fix: always validate versions whenever a state sync is accessed (#769)
1 parent 8deaae5 commit c143dac

File tree

6 files changed

+10
-7
lines changed

6 files changed

+10
-7
lines changed

examples/multi/repo_1/config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ connections:
55
type: duckdb
66
database: db.db
77

8+
memory:
9+
type: duckdb
10+
811
default_connection: local

examples/multi/repo_2/config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ connections:
55
type: duckdb
66
database: db.db
77

8+
memory:
9+
type: duckdb
10+
811
default_connection: local

sqlmesh/core/context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ def state_sync(self) -> StateSync:
319319

320320
if self._state_sync.get_versions(validate=False).schema_version == 0:
321321
self._state_sync.migrate()
322+
self._state_sync.get_versions()
322323
return self._state_sync
323324

324325
@property

sqlmesh/core/state_sync/engine_adapter.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ def _get_snapshots(
289289
self,
290290
snapshot_ids: t.Optional[t.Iterable[SnapshotIdLike]] = None,
291291
lock_for_update: bool = False,
292-
validate_versions: bool = True,
293292
) -> t.Dict[SnapshotId, Snapshot]:
294293
"""Fetches specified snapshots or all snapshots.
295294
@@ -300,9 +299,6 @@ def _get_snapshots(
300299
Returns:
301300
A dictionary of snapshot ids to snapshots for ones that could be found.
302301
"""
303-
if validate_versions:
304-
self.get_versions()
305-
306302
query = (
307303
exp.select("snapshot")
308304
.from_(self.snapshots_table)
@@ -406,7 +402,7 @@ def migrate(self) -> None:
406402
super().migrate()
407403

408404
def _migrate_rows(self) -> None:
409-
all_snapshots = self._get_snapshots(lock_for_update=True, validate_versions=False)
405+
all_snapshots = self._get_snapshots(lock_for_update=True)
410406
environments = self.get_environments()
411407

412408
snapshot_mapping = {}

sqlmesh/migrations/v0004_environmnent_add_finalized_at.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
def migrate(state_sync): # type: ignore
66
engine_adapter = state_sync.engine_adapter
7-
environments_table = state_sync.environments_table
7+
environments_table = f"{state_sync.schema}._environments"
88

99
alter_table_exp = exp.AlterTable(
1010
this=exp.to_table(environments_table),

tests/core/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def test_auto_categorization(sushi_context: Context):
627627
@pytest.mark.integration
628628
@pytest.mark.core_integration
629629
def test_multi(mocker):
630-
context = Context(paths=["examples/multi/repo_1", "examples/multi/repo_2"])
630+
context = Context(paths=["examples/multi/repo_1", "examples/multi/repo_2"], config="memory")
631631
context.state_sync.reset()
632632
plan = context.plan()
633633
assert len(plan.new_snapshots) == 4

0 commit comments

Comments
 (0)