Skip to content

Commit b8f4a29

Browse files
committed
Remove physical grants application in promotion stage.
Physical grants are applied in migration when there are metadata only changes.
1 parent ca03fcf commit b8f4a29

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

sqlmesh/core/snapshot/evaluator.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,9 +1855,6 @@ def promote(
18551855
else False
18561856
)
18571857

1858-
# Apply grants to the physical layer (referenced table / view) after promotion
1859-
self._apply_grants(model, table_name, GrantsTargetLayer.PHYSICAL, is_snapshot_deployable)
1860-
18611858
# Apply grants to the virtual layer (view) after promotion
18621859
self._apply_grants(model, view_name, GrantsTargetLayer.VIRTUAL, is_snapshot_deployable)
18631860

tests/core/test_context.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,7 +3199,9 @@ def test_grants_through_plan_apply(sushi_context, mocker):
31993199

32003200
sushi_context.plan("dev", no_prompts=True, auto_apply=True)
32013201

3202-
assert sync_grants_mock.call_count == 2
3202+
# When planning for dev env w/ metadata only changes,
3203+
# only virtual layer is updated, so no physical grants are applied
3204+
assert sync_grants_mock.call_count == 1
32033205
assert all(
32043206
call[0][1] == {"select": ["analyst", "reporter"]}
32053207
for call in sync_grants_mock.call_args_list
@@ -3212,15 +3214,19 @@ def test_grants_through_plan_apply(sushi_context, mocker):
32123214
update={
32133215
"query": parse_one(model.query.sql() + " LIMIT 1000"),
32143216
"grants": new_grants,
3217+
# force model update, hence new physical table creation
32153218
"stamp": "update model and grants",
32163219
}
32173220
)
32183221
sushi_context.upsert_model(model_updated)
3219-
32203222
sushi_context.plan("dev", no_prompts=True, auto_apply=True)
32213223

3222-
# Applies grants 3 times:
3223-
# 2 x physical (duplicated): create, promote (will diff but won't apply since it's the same grants)
3224-
# 1 x virtual
3225-
assert sync_grants_mock.call_count == 3
3224+
# Applies grants 2 times: 1 x physical, 1 x virtual
3225+
assert sync_grants_mock.call_count == 2
32263226
assert all(call[0][1] == new_grants for call in sync_grants_mock.call_args_list)
3227+
3228+
sync_grants_mock.reset_mock()
3229+
3230+
# plan for prod
3231+
sushi_context.plan(no_prompts=True, auto_apply=True)
3232+
assert sync_grants_mock.call_count == 2

0 commit comments

Comments
 (0)