Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions sqlmesh/core/model/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,7 @@ def render_definition(
value=exp.to_table(field_value, dialect=self.dialect),
)
)
elif field_name not in (
"column_descriptions_",
"default_catalog",
"enabled",
"inline_audits",
"optimize_query",
"ignored_rules_",
):
elif field_name not in ("default_catalog", "enabled", "ignored_rules_"):
expressions.append(
exp.Property(
this=field_info.alias or field_name,
Expand Down Expand Up @@ -2940,6 +2933,9 @@ def render_expression(
"columns_to_types_": lambda value: exp.Schema(
expressions=[exp.ColumnDef(this=exp.to_column(c), kind=t) for c, t in value.items()]
),
"column_descriptions_": lambda value: exp.Schema(
expressions=[exp.to_column(c).eq(d) for c, d in value.items()]
),
"tags": single_value_or_tuple,
"grains": _refs_to_sql,
"references": _refs_to_sql,
Expand All @@ -2958,6 +2954,7 @@ def render_expression(
)
),
"formatting": str,
"optimize_query": str,
"virtual_environment_mode": lambda value: exp.Literal.string(value.value),
}

Expand Down
49 changes: 49 additions & 0 deletions tests/core/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11359,3 +11359,52 @@ def test_extract_macro_func_variable_references(macro_func: str, variables: t.Se

macro_func_ast = parse_one(macro_func)
assert _extract_macro_func_variable_references(macro_func_ast, True)[0] == variables


def test_text_diff_column_descriptions():
"""Test that column_descriptions changes are visible in text_diff."""
# Create model without column descriptions
model1 = create_sql_model(
name="test.model",
query=parse("SELECT id, name FROM upstream")[0],
)

# Create model with column descriptions
model2 = create_sql_model(
name="test.model",
query=parse("SELECT id, name FROM upstream")[0],
column_descriptions={"id": "User identifier", "name": "User name"},
)

# Verify the diff shows the column_descriptions
diff = model1.text_diff(model2)
assert diff, "Expected diff to show column_descriptions change"
assert "+ id = 'User identifier'," in diff
assert "+ name = 'User name'" in diff

# Verify reverse diff also works
diff = model2.text_diff(model1)
assert diff, "Expected reverse diff to show column_descriptions removal"
assert "- id = 'User identifier'," in diff
assert "- name = 'User name'" in diff


def test_text_diff_optimize_query():
"""Test that optimize_query changes are visible in text_diff."""
# Create model without optimize_query
model1 = create_sql_model(
name="test.model",
query=parse("SELECT id, name FROM upstream")[0],
)

# Create model with optimize_query enabled
model2 = create_sql_model(
name="test.model",
query=parse("SELECT id, name FROM upstream")[0],
optimize_query=True,
)

# Verify the diff shows the optimize_query change
diff = model1.text_diff(model2)
assert diff, "Expected diff to show optimize_query change"
assert "+ optimize_query" in diff.lower()
2 changes: 1 addition & 1 deletion tests/integrations/github/cicd/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ def test_overlapping_changes_models(

+++

@@ -29,7 +29,8 @@
@@ -32,7 +32,8 @@

SELECT DISTINCT
CAST(o.customer_id AS INT) AS customer_id,
Expand Down