Skip to content

fix: prioritize @EACH lambda params over column name conflicts#5769

Open
MubinUmarov wants to merge 2 commits intoSQLMesh:mainfrom
MubinUmarov:fix/each-lambda-param-column-name-conflict
Open

fix: prioritize @EACH lambda params over column name conflicts#5769
MubinUmarov wants to merge 2 commits intoSQLMesh:mainfrom
MubinUmarov:fix/each-lambda-param-column-name-conflict

Conversation

@MubinUmarov
Copy link
Copy Markdown

Summary

  • Fixed silent @EACH() failure when the lambda parameter name matches an existing column name
  • Lambda arguments (args) now take priority over Column context checks
  • evaluator.locals substitution remains restricted to non-Column nodes (unchanged behavior)

Root Cause

In _norm_var_arg_lambda (sqlmesh/core/macros.py), the substitute function wrapped both args and evaluator.locals lookups inside if not isinstance(node.parent, exp.Column). This caused the lambda parameter to be silently skipped when it appeared as a column reference.

Test plan

  • Added two test cases to tests/core/test_macros.py covering @EACH with lambda parameter names that conflict with column names
  • All 138 tests in test_macros.py pass

Fixes #5582

🤖 Generated with Claude Code

MubinUmarov and others added 2 commits April 19, 2026 23:13
When a lambda parameter name matched an existing column name, the
substitution was silently skipped due to the `not isinstance(node.parent,
exp.Column)` guard wrapping both `args` and `evaluator.locals` lookups.

Lambda arguments now take priority regardless of Column context, while
`evaluator.locals` substitution remains restricted to non-Column nodes.

Fixes SQLMesh#5582

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tobymao
Copy link
Copy Markdown
Contributor

tobymao commented Apr 20, 2026

@MubinUmarov thanks, please fix the build

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.

Silent @EACH() failure when second argument matches column name in node

2 participants