Skip to content

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

Merged
StuffbyYuki merged 1 commit into
SQLMesh:mainfrom
MubinUmarov:fix/each-lambda-param-column-name-conflict
Jun 26, 2026
Merged

fix: prioritize @EACH lambda params over column name conflicts#5769
StuffbyYuki merged 1 commit into
SQLMesh:mainfrom
MubinUmarov:fix/each-lambda-param-column-name-conflict

Conversation

@MubinUmarov

Copy link
Copy Markdown
Contributor

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

@tobymao

tobymao commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

@MubinUmarov thanks, please fix the build

@StuffbyYuki

Copy link
Copy Markdown
Collaborator

@MubinUmarov Following up on the prev comment!

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>
Signed-off-by: Mubin Umarov <mubin.umarov@gmail.com>
@MubinUmarov MubinUmarov force-pushed the fix/each-lambda-param-column-name-conflict branch from dcc9f3b to 0692972 Compare June 26, 2026 20:04
@MubinUmarov

Copy link
Copy Markdown
Contributor Author

The failing test test_freeze_time_concurrent on Python 3.9 appears to be a pre-existing flaky test unrelated to this change — it passes locally and on all other Python versions (3.10, 3.11, 3.12, 3.13) in CI.

@StuffbyYuki

Copy link
Copy Markdown
Collaborator

yeah i guess those tests fail here and there ramdomly. Just kicked it off, let's see how it goes

@StuffbyYuki StuffbyYuki merged commit 991a327 into SQLMesh:main Jun 26, 2026
62 of 63 checks passed
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

3 participants