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
12 changes: 10 additions & 2 deletions sqlmesh/core/model/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,18 @@ def parse_expression(


def parse_bool(v: t.Any) -> bool:
if isinstance(v, exp.Boolean):
return v.this
if isinstance(v, exp.Expression):
Copy link
Copy Markdown
Collaborator Author

@georgesittas georgesittas Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've verified by putting an exit(1) within this branch that it wasn't reached by any of our tests, prior to this PR. The only dialect I'm aware of being impacted by this change is T-SQL.

if not isinstance(v, exp.Boolean):
from sqlglot.optimizer.simplify import simplify

# Try to reduce expressions like (1 = 1) (see: T-SQL boolean generation)
v = simplify(v)

if isinstance(v, exp.Boolean):
return v.this

return str_to_bool(v.name)

return str_to_bool(str(v or ""))


Expand Down
18 changes: 17 additions & 1 deletion tests/core/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10445,7 +10445,7 @@ def test_invalid_sql_model_query() -> None:
load_sql_based_model(expressions)


def test_query_label_and_authorization_macro():
def test_query_label_and_authorization_macro() -> None:
@macro()
def test_query_label_macro(evaluator):
return "[('key', 'value')]"
Expand Down Expand Up @@ -10478,3 +10478,19 @@ def test_authorization_macro(evaluator):
"query_label": d.parse_one("[('key', 'value')]"),
"authorization": d.parse_one("'test_authorization'"),
}


def test_boolean_property_validation() -> None:
expressions = d.parse(
"""
MODEL (
name db.table,
enabled @IF(TRUE, TRUE, FALSE),
dialect tsql
);

SELECT 1 AS c;
"""
)
model = load_sql_based_model(expressions, dialect="tsql")
assert model.enabled