Skip to content

Commit 54ca124

Browse files
committed
fix: allow sync_grants_config to be duplicated on when planned w/ create and promote
1 parent 03e709c commit 54ca124

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

sqlmesh/core/snapshot/evaluator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,6 @@ def create_snapshot(
873873
deployability_index=deployability_index,
874874
create_render_kwargs=create_render_kwargs,
875875
rendered_physical_properties=rendered_physical_properties,
876-
skip_grants=True,
877876
dry_run=True,
878877
)
879878

@@ -1429,7 +1428,7 @@ def _can_clone(self, snapshot: Snapshot, deployability_index: DeployabilityIndex
14291428
and snapshot.is_materialized
14301429
and bool(snapshot.previous_versions)
14311430
and adapter.SUPPORTS_CLONING
1432-
# managed models cannot have their schema mutated because theyre based on queries, so clone + alter wont work
1431+
# managed models cannot have their schema mutated because they're based on queries, so clone + alter won't work
14331432
and not snapshot.is_managed
14341433
# If the deployable table is missing we can't clone it
14351434
and not deployability_index.is_deployable(snapshot)

tests/core/test_context.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,7 @@ def test_grants_through_plan_apply(sushi_context, mocker):
31853185
from sqlmesh.core.model.meta import GrantsTargetLayer
31863186

31873187
model = sushi_context.get_model("sushi.waiter_revenue_by_day")
3188+
31883189
mocker.patch.object(DuckDBEngineAdapter, "SUPPORTS_GRANTS", True)
31893190
sync_grants_mock = mocker.patch.object(DuckDBEngineAdapter, "sync_grants_config")
31903191

@@ -3206,18 +3207,20 @@ def test_grants_through_plan_apply(sushi_context, mocker):
32063207

32073208
sync_grants_mock.reset_mock()
32083209

3210+
new_grants = ({"select": ["analyst", "reporter", "manager"], "insert": ["etl_user"]},)
32093211
model_updated = model_with_grants.copy(
32103212
update={
32113213
"query": parse_one(model.query.sql() + " LIMIT 1000"),
3212-
"grants": {"select": ["analyst", "reporter", "manager"], "insert": ["etl_user"]},
3214+
"grants": new_grants,
32133215
"stamp": "update model and grants",
32143216
}
32153217
)
32163218
sushi_context.upsert_model(model_updated)
32173219

32183220
sushi_context.plan("dev", no_prompts=True, auto_apply=True)
32193221

3220-
assert sync_grants_mock.call_count == 2
3221-
3222-
expected_grants = {"select": ["analyst", "reporter", "manager"], "insert": ["etl_user"]}
3223-
assert all(call[0][1] == expected_grants for call in sync_grants_mock.call_args_list)
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
3226+
assert all(call[0][1] == new_grants for call in sync_grants_mock.call_args_list)

0 commit comments

Comments
 (0)