Skip to content

Commit 6a63673

Browse files
committed
Fix: Pass the model dialect when computing a hash for the column types
1 parent 3ea0493 commit 6a63673

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

sqlmesh/core/model/definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ def _data_hash_values(self) -> t.List[str]:
10511051

10521052
for column_name, column_type in (self.columns_to_types_ or {}).items():
10531053
data.append(column_name)
1054-
data.append(column_type.sql())
1054+
data.append(column_type.sql(dialect=self.dialect))
10551055

10561056
for key, value in (self.physical_properties or {}).items():
10571057
data.append(key)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Use the model's dialect when calculating the hash for the column types."""
2+
3+
4+
def migrate(state_sync, **kwargs): # type: ignore
5+
pass

tests/core/test_model.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8435,3 +8435,20 @@ def test_ignored_rules_serialization():
84358435

84368436
deserialized_model = SqlModel.parse_raw(model_json)
84378437
assert deserialized_model.dict() == model.dict()
8438+
8439+
8440+
def test_data_hash_unchanged_when_column_type_uses_default_dialect():
8441+
model = create_sql_model(
8442+
"foo",
8443+
parse_one("SELECT * FROM bla"),
8444+
columns={"a": exp.DataType.build("int")},
8445+
dialect="bigquery",
8446+
)
8447+
8448+
deserialized_model = SqlModel.parse_raw(model.json())
8449+
8450+
assert model.columns_to_types_ == {"a": exp.DataType.build("int")}
8451+
assert deserialized_model.columns_to_types_ == {"a": exp.DataType.build("bigint")}
8452+
8453+
# int == int64 in bigquery
8454+
assert model.data_hash == deserialized_model.data_hash

0 commit comments

Comments
 (0)