Skip to content

Commit d7d96b0

Browse files
committed
Pass snapshots and deployability_index to session properties renderer
1 parent 4f2e901 commit d7d96b0

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

sqlmesh/core/plan/evaluator.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ def visit_virtual_layer_update_stage(
336336
self._demote_snapshots(
337337
[stage.all_snapshots[s.snapshot_id] for s in stage.demoted_snapshots],
338338
stage.demoted_environment_naming_info,
339+
snapshots=stage.all_snapshots,
340+
deployability_index=stage.deployability_index,
339341
on_complete=lambda s: self.console.update_promotion_progress(s, False),
340342
)
341343

@@ -378,10 +380,16 @@ def _demote_snapshots(
378380
self,
379381
target_snapshots: t.Iterable[Snapshot],
380382
environment_naming_info: EnvironmentNamingInfo,
383+
snapshots: t.Dict[SnapshotId, Snapshot],
384+
deployability_index: t.Optional[DeployabilityIndex] = None,
381385
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]] = None,
382386
) -> None:
383387
self.snapshot_evaluator.demote(
384-
target_snapshots, environment_naming_info, on_complete=on_complete
388+
target_snapshots,
389+
environment_naming_info,
390+
snapshots=snapshots,
391+
deployability_index=deployability_index,
392+
on_complete=on_complete,
385393
)
386394

387395
def _restatement_intervals_across_all_environments(

sqlmesh/core/snapshot/evaluator.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ def demote(
277277
self,
278278
target_snapshots: t.Iterable[Snapshot],
279279
environment_naming_info: EnvironmentNamingInfo,
280+
snapshots: t.Dict[SnapshotId, Snapshot],
281+
deployability_index: t.Optional[DeployabilityIndex] = None,
280282
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]] = None,
281283
) -> None:
282284
"""Demotes the given collection of snapshots in the target environment by removing its view.
@@ -289,7 +291,9 @@ def demote(
289291
with self.concurrent_context():
290292
concurrent_apply_to_snapshots(
291293
target_snapshots,
292-
lambda s: self._demote_snapshot(s, environment_naming_info, on_complete),
294+
lambda s: self._demote_snapshot(
295+
s, environment_naming_info, snapshots, deployability_index, on_complete
296+
),
293297
self.ddl_concurrent_tasks,
294298
)
295299

@@ -1013,6 +1017,8 @@ def _demote_snapshot(
10131017
self,
10141018
snapshot: Snapshot,
10151019
environment_naming_info: EnvironmentNamingInfo,
1020+
snapshots: t.Dict[SnapshotId, Snapshot],
1021+
deployability_index: t.Optional[DeployabilityIndex],
10161022
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]],
10171023
) -> None:
10181024
if snapshot.is_model:
@@ -1028,7 +1034,10 @@ def _demote_snapshot(
10281034
adapter.transaction(),
10291035
adapter.session(
10301036
snapshot.model.render_session_properties(
1031-
engine_adapter=adapter, runtime_stage=RuntimeStage.PROMOTING
1037+
engine_adapter=adapter,
1038+
snapshots=snapshots,
1039+
deployability_index=deployability_index,
1040+
runtime_stage=RuntimeStage.PROMOTING,
10321041
)
10331042
),
10341043
):

sqlmesh/engines/commands.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ class PromoteCommandPayload(PydanticModel):
4848

4949

5050
class DemoteCommandPayload(PydanticModel):
51-
snapshots: t.List[Snapshot]
51+
target_snapshots: t.List[Snapshot]
5252
environment_naming_info: EnvironmentNamingInfo
53+
snapshots: t.Dict[SnapshotId, Snapshot]
54+
deployability_index: DeployabilityIndex
5355

5456

5557
class CleanupCommandPayload(PydanticModel):
@@ -128,8 +130,10 @@ def demote(
128130
if isinstance(command_payload, str):
129131
command_payload = DemoteCommandPayload.parse_raw(command_payload)
130132
evaluator.demote(
131-
command_payload.snapshots,
133+
command_payload.target_snapshots,
132134
command_payload.environment_naming_info,
135+
snapshots=command_payload.snapshots,
136+
deployability_index=command_payload.deployability_index,
133137
)
134138

135139

tests/core/test_snapshot_evaluator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def test_demote(mocker: MockerFixture, adapter_mock, make_snapshot):
320320
snapshot = make_snapshot(model)
321321
snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
322322

323-
evaluator.demote([snapshot], EnvironmentNamingInfo(name="test_env"))
323+
evaluator.demote([snapshot], EnvironmentNamingInfo(name="test_env"), snapshots={})
324324

325325
adapter_mock.transaction.assert_called()
326326
adapter_mock.session.assert_called()
@@ -2711,7 +2711,7 @@ def test_standalone_audit(mocker: MockerFixture, adapter_mock, make_snapshot):
27112711
adapter_mock.session.assert_not_called()
27122712

27132713
# Demote
2714-
evaluator.demote([snapshot], EnvironmentNamingInfo(name="test_env"))
2714+
evaluator.demote([snapshot], EnvironmentNamingInfo(name="test_env"), snapshots={})
27152715

27162716
adapter_mock.assert_not_called()
27172717
adapter_mock.transaction.assert_not_called()
@@ -3854,7 +3854,7 @@ def test_multiple_engine_creation(snapshot: Snapshot, adapters, make_snapshot):
38543854
assert len(post_calls) == 1
38553855
assert post_calls[0].sql(dialect="postgres") == expected_call
38563856

3857-
evaluator.demote([snapshot_2], EnvironmentNamingInfo(name="test_env"))
3857+
evaluator.demote([snapshot_2], EnvironmentNamingInfo(name="test_env"), snapshots={})
38583858
engine_adapters["secondary"].drop_view.assert_not_called()
38593859
engine_adapters["default"].drop_view.assert_called_once_with(
38603860
"test_schema__test_env.test_model",
@@ -4100,7 +4100,7 @@ def model_with_statements(context, **kwargs):
41004100
engine_adapters["default"].get_catalog_type.assert_not_called()
41014101
assert len(engine_adapters["secondary"].get_catalog_type.call_args_list) == 2
41024102

4103-
evaluator.demote([snapshot], environment_naming_info)
4103+
evaluator.demote([snapshot], environment_naming_info, snapshots={})
41044104
engine_adapters["default"].drop_view.assert_called_once_with(
41054105
"db__test_env.multi_engine_test_model",
41064106
cascade=False,
@@ -4114,7 +4114,7 @@ def model_with_statements(context, **kwargs):
41144114
assert view_args[0][0][0] == "db__test_env.multi_engine_test_model"
41154115

41164116
# Similarly for demotion
4117-
evaluator.demote([snapshot], environment_naming_info_gw)
4117+
evaluator.demote([snapshot], environment_naming_info_gw, snapshots={})
41184118
engine_adapters["secondary"].drop_view.assert_called_once_with(
41194119
"db__test_env.multi_engine_test_model",
41204120
cascade=False,
@@ -4172,7 +4172,7 @@ def test_multiple_engine_virtual_layer(snapshot: Snapshot, adapters, make_snapsh
41724172
assert view_args_secondary[0][0][0] == "test_schema__test_env.test_model"
41734173

41744174
# Demotion will follow with the same pattern
4175-
evaluator.demote([snapshot_2, snapshot], environment_naming_info)
4175+
evaluator.demote([snapshot_2, snapshot], environment_naming_info, snapshots={})
41764176
engine_adapters["default"].drop_view.assert_called_once_with(
41774177
"db__test_env.model",
41784178
cascade=False,

0 commit comments

Comments
 (0)