Skip to content

Commit 0c81ea6

Browse files
committed
fix: apply grants to the physical layer table on promote
1 parent 675d316 commit 0c81ea6

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

sqlmesh/core/snapshot/evaluator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,9 @@ def promote(
17951795
view_properties=model.render_virtual_properties(**render_kwargs),
17961796
)
17971797

1798+
# Apply grants to the physical layer table
1799+
self._apply_grants(model, table_name, GrantsTargetLayer.PHYSICAL)
1800+
17981801
# Apply grants to the virtual layer view
17991802
self._apply_grants(model, view_name, GrantsTargetLayer.VIRTUAL)
18001803

tests/core/test_snapshot_evaluator.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4782,17 +4782,15 @@ def test_grants_create_model_kind(
47824782

47834783

47844784
@pytest.mark.parametrize(
4785-
"target_layer,apply_on_create,apply_on_promote",
4785+
"target_layer",
47864786
[
4787-
(GrantsTargetLayer.PHYSICAL, True, False),
4788-
(GrantsTargetLayer.VIRTUAL, False, True),
4789-
(GrantsTargetLayer.ALL, True, True),
4787+
GrantsTargetLayer.PHYSICAL,
4788+
GrantsTargetLayer.VIRTUAL,
4789+
GrantsTargetLayer.ALL,
47904790
],
47914791
)
47924792
def test_grants_target_layer(
47934793
target_layer: GrantsTargetLayer,
4794-
apply_on_create: bool,
4795-
apply_on_promote: bool,
47964794
adapter_mock: Mock,
47974795
mocker: MockerFixture,
47984796
make_snapshot: t.Callable[..., Snapshot],
@@ -4814,19 +4812,17 @@ def test_grants_target_layer(
48144812
snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
48154813

48164814
evaluator.create([snapshot], {})
4817-
if apply_on_create:
4818-
sync_grants_mock.assert_called_once()
4819-
assert sync_grants_mock.call_args[0][1] == grants
4815+
if target_layer == GrantsTargetLayer.VIRTUAL:
4816+
assert sync_grants_mock.call_count == 0
48204817
else:
4821-
sync_grants_mock.assert_not_called()
4822-
4818+
assert sync_grants_mock.call_count == 1
4819+
assert sync_grants_mock.call_args[0][1] == grants
48234820
sync_grants_mock.reset_mock()
48244821
evaluator.promote([snapshot], EnvironmentNamingInfo(name="prod"))
4825-
if apply_on_promote:
4826-
sync_grants_mock.assert_called_once()
4827-
assert sync_grants_mock.call_args[0][1] == grants
4822+
if target_layer == GrantsTargetLayer.ALL:
4823+
assert sync_grants_mock.call_count == 2
48284824
else:
4829-
sync_grants_mock.assert_not_called()
4825+
assert sync_grants_mock.call_count == 1
48304826

48314827

48324828
def test_grants_update(

0 commit comments

Comments
 (0)