Skip to content

fix: Swap parser override order for macro IF under T-SQL (Issue #5823)#5828

Open
jagannalla wants to merge 1 commit into
SQLMesh:mainfrom
jagannalla:fix/tsql-macro-if-5823
Open

fix: Swap parser override order for macro IF under T-SQL (Issue #5823)#5828
jagannalla wants to merge 1 commit into
SQLMesh:mainfrom
jagannalla:fix/tsql-macro-if-5823

Conversation

@jagannalla
Copy link
Copy Markdown

@jagannalla jagannalla commented Jun 4, 2026

Summary

This PR fixes a bug where conditional macro statements (e.g. @IF(cond, statement)) using the T-SQL / MSSQL dialect would fail validation with:
Required keyword: 'true' missing for <class 'sqlglot.expressions.functions.If'>

Root Cause

In extend_sqlglot() within sqlmesh/core/dialect.py, the overrides were registered in the wrong order:

_override(TSQL.Parser, Parser._parse_if)
_override(Parser, _parse_if)

Solution

  1. Swapped the registration lines in sqlmesh/core/dialect.py so the custom parser wrapper is registered on the base Parser first.
  2. Added unit tests under tests/core/test_dialect.py for T-SQL-specific statements parsed within @IF.

Link to Issue

Closes #5823

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Required keyword: 'true' missing for <class 'sqlglot.expressions.functions.If'>

2 participants