Skip to content

Commit 03e0948

Browse files
committed
fix: apply grants to the physical layer table on promote
1 parent 9cd34df commit 03e0948

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
@@ -1809,6 +1809,9 @@ def promote(
18091809
view_properties=model.render_virtual_properties(**render_kwargs),
18101810
)
18111811

1812+
# Apply grants to the physical layer table
1813+
self._apply_grants(model, table_name, GrantsTargetLayer.PHYSICAL)
1814+
18121815
# Apply grants to the virtual layer view
18131816
self._apply_grants(model, view_name, GrantsTargetLayer.VIRTUAL)
18141817

tests/core/test_snapshot_evaluator.py

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

47894789

47904790
@pytest.mark.parametrize(
4791-
"target_layer,apply_on_create,apply_on_promote",
4791+
"target_layer",
47924792
[
4793-
(GrantsTargetLayer.PHYSICAL, True, False),
4794-
(GrantsTargetLayer.VIRTUAL, False, True),
4795-
(GrantsTargetLayer.ALL, True, True),
4793+
GrantsTargetLayer.PHYSICAL,
4794+
GrantsTargetLayer.VIRTUAL,
4795+
GrantsTargetLayer.ALL,
47964796
],
47974797
)
47984798
def test_grants_target_layer(
47994799
target_layer: GrantsTargetLayer,
4800-
apply_on_create: bool,
4801-
apply_on_promote: bool,
48024800
adapter_mock: Mock,
48034801
mocker: MockerFixture,
48044802
make_snapshot: t.Callable[..., Snapshot],
@@ -4820,19 +4818,17 @@ def test_grants_target_layer(
48204818
snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
48214819

48224820
evaluator.create([snapshot], {})
4823-
if apply_on_create:
4824-
sync_grants_mock.assert_called_once()
4825-
assert sync_grants_mock.call_args[0][1] == grants
4821+
if target_layer == GrantsTargetLayer.VIRTUAL:
4822+
assert sync_grants_mock.call_count == 0
48264823
else:
4827-
sync_grants_mock.assert_not_called()
4828-
4824+
assert sync_grants_mock.call_count == 1
4825+
assert sync_grants_mock.call_args[0][1] == grants
48294826
sync_grants_mock.reset_mock()
48304827
evaluator.promote([snapshot], EnvironmentNamingInfo(name="prod"))
4831-
if apply_on_promote:
4832-
sync_grants_mock.assert_called_once()
4833-
assert sync_grants_mock.call_args[0][1] == grants
4828+
if target_layer == GrantsTargetLayer.ALL:
4829+
assert sync_grants_mock.call_count == 2
48344830
else:
4835-
sync_grants_mock.assert_not_called()
4831+
assert sync_grants_mock.call_count == 1
48364832

48374833

48384834
def test_grants_update(

0 commit comments

Comments
 (0)