Skip to content

Commit 1ca93cd

Browse files
committed
fix: force seed model to rebuild on grant changes
since seed models don't support migration
1 parent 1f70c98 commit 1ca93cd

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
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

0 commit comments

Comments
 (0)