Skip to content

Commit 89fe577

Browse files
committed
fix: force seed model to rebuild on grant changes
since seed models don't support migration
1 parent 8e84e53 commit 89fe577

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

sqlmesh/core/model/definition.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,12 @@ def _data_hash_values_no_sql(self) -> t.List[str]:
18441844
for column_name, column_hash in self.column_hashes.items():
18451845
data.append(column_name)
18461846
data.append(column_hash)
1847+
1848+
# Include grants in data hash for seed models to force recreation on grant changes
1849+
# since seed models don't support migration
1850+
data.append(json.dumps(self.grants, sort_keys=True) if self.grants else "")
1851+
data.append(self.grants_target_layer)
1852+
18471853
return data
18481854

18491855

tests/core/engine_adapter/integration/test_integration_postgres.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,13 +698,18 @@ def test_grants_metadata_only_changes(
698698
"insert": [roles["admin"]["username"]],
699699
},
700700
)
701-
context.plan(auto_apply=True, no_prompts=True)
701+
second_plan_result = context.plan(auto_apply=True, no_prompts=True)
702702

703703
expected_grants = {
704704
"SELECT": [roles["writer"]["username"], roles["admin"]["username"]],
705705
"INSERT": [roles["admin"]["username"]],
706706
}
707707

708+
# For seed models, grant changes rebuild the entire table, so it will create a new physical table
709+
if model_name == "grants_seed" and second_plan_result.new_snapshots:
710+
updated_snapshot = second_plan_result.new_snapshots[0]
711+
physical_table_name = updated_snapshot.table_name()
712+
708713
updated_physical_grants = engine_adapter._get_current_grants_config(
709714
exp.to_table(physical_table_name, dialect=engine_adapter.dialect)
710715
)

tests/core/test_snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ def test_fingerprint_seed_model():
10451045
)
10461046

10471047
expected_fingerprint = SnapshotFingerprint(
1048-
data_hash="1586624913",
1048+
data_hash="2112858704",
10491049
metadata_hash="2674364560",
10501050
)
10511051

tests/core/test_snapshot_evaluator.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
IncrementalUnmanagedStrategy,
6868
MaterializableStrategy,
6969
SCDType2Strategy,
70-
SeedStrategy,
7170
SnapshotCreationFailedError,
7271
ViewStrategy,
7372
)
@@ -5048,9 +5047,13 @@ def test_grants_target_layer(
50485047
assert sync_grants_mock.call_args[0][1] == grants
50495048
sync_grants_mock.reset_mock()
50505049
evaluator.promote([snapshot], EnvironmentNamingInfo(name="prod"))
5051-
if target_layer == GrantsTargetLayer.ALL:
5052-
assert sync_grants_mock.call_count == 2
5053-
else:
5050+
if target_layer == GrantsTargetLayer.VIRTUAL:
5051+
assert sync_grants_mock.call_count == 1
5052+
elif target_layer == GrantsTargetLayer.PHYSICAL:
5053+
# Physical layer: no grants applied during promotion (already applied during create)
5054+
assert sync_grants_mock.call_count == 0
5055+
else: # target_layer == GrantsTargetLayer.ALL
5056+
# All layers: only virtual grants applied during promotion (physical already done in create)
50545057
assert sync_grants_mock.call_count == 1
50555058

50565059

@@ -5161,7 +5164,7 @@ def test_grants_create_and_evaluate(
51615164
IncrementalUnmanagedStrategy,
51625165
IncrementalByUniqueKeyStrategy,
51635166
SCDType2Strategy,
5164-
SeedStrategy,
5167+
# SeedStrategy excluded because seeds do not support migrations
51655168
],
51665169
)
51675170
def test_grants_materializable_strategy_migrate(

0 commit comments

Comments
 (0)