Skip to content

Fix!: Improve tracking of var dependencies in dbt models #5204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 22, 2025

Conversation

izeigerman
Copy link
Member

@izeigerman izeigerman commented Aug 21, 2025

This update improves the SQLMesh's ability to track variable dependencies for dbt models by adding a limited support for variable names that can't be determined statically.

If static analysis determines that the value of the first argument to the {{ var() }} macro call cannot be resolved, the Jinja string(s) will be rendered using a stub adapter implementation along with a {{ var() }} macro override that captures the variable names passed into the macro during rendering.

This approach is far from bulletproof, as rendering with the stub adapter may (and likely will) result in traversing code branches different from those that would be taken with the runtime adapter. At the same time, this approach is consistent with how dbt-core itself collects ref and source dependencies.

UPD: After further deliberation, we decided to unconditionally include ALL variables associated with a package if dynamic variable names are detected. This is due to the high risk of not capturing the correct variables during rendering, which could lead to incorrect runtime behavior in cases where dbt would have worked as expected.

@izeigerman izeigerman requested a review from a team August 21, 2025 20:15
@izeigerman izeigerman force-pushed the fix-better-tracking-for-dbt-vars branch from 2259d22 to 7627d91 Compare August 21, 2025 20:23
@izeigerman izeigerman force-pushed the fix-better-tracking-for-dbt-vars branch 3 times, most recently from ad0475c to 0ba3391 Compare August 22, 2025 18:07
@izeigerman izeigerman changed the title Fix: Improve tracking of var dependencies in dbt models Fix!: Improve tracking of var dependencies in dbt models Aug 22, 2025
@izeigerman izeigerman force-pushed the fix-better-tracking-for-dbt-vars branch from 0ba3391 to 0dc51e7 Compare August 22, 2025 18:46
@izeigerman izeigerman force-pushed the fix-better-tracking-for-dbt-vars branch from 0dc51e7 to af8f31b Compare August 22, 2025 22:39
@izeigerman izeigerman merged commit 4209672 into main Aug 22, 2025
28 checks passed
@izeigerman izeigerman deleted the fix-better-tracking-for-dbt-vars branch August 22, 2025 23:13
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.

2 participants