fix: use restricted Jinja context for macro property resolution#1577
fix: use restricted Jinja context for macro property resolution#1577yxshwanth wants to merge 1 commit intodbt-labs:mainfrom
Conversation
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Yashwanth Reddy Mali.
|
|
This repository enforces signed commits. Please sign your commits by following the docs here. |
2512548 to
a296c04
Compare
|
Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA. In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, please reach out through a comment on this PR. CLA has not been signed by users: @yxshwanth |
Match dbt Core by preventing project/package macro execution while rendering macro properties YAML descriptions, while preserving doc() and parse metadata context.
a296c04 to
73e1c3a
Compare
|
Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA. In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, please reach out through a comment on this PR. CLA has not been signed by users: @yxshwanth |
Problem
Resolves #1576
Jinja expressions inside a macro's
description:field in schema YAML areevaluated at parse time using the full project macro context. This causes
{{ cents_to_dollars('price_cents') }}to silently render toprice_cents / 100.0inmanifest.json. In dbt Core, the same expressioncauses a parse error ("undefined"), which is the correct behavior.
Solution
Add
build_macro_properties_resolve_contextinresolve_context.rs, whichconstructs the same Jinja environment as
build_resolve_contextbut passesno
namespace_keys— so noDbtNamespaceentries (project/package macros)are injected. This restricted context is threaded through two call sites:
resolve_propertiesandapply_macro_patches.What still works:
doc(),target,execute,de,connection_name, dispatch order.What's blocked: Arbitrary project macro calls (e.g.
{{ cents_to_dollars(...) }}) in macro description fields — matchingdbt Core behavior.
Tests
Three tests in
resolve_context.rsunder#[cfg(test)]:macro_properties_context_omits_macro_namespace_keys— structural:narrow context has no
dbt/local_pkgkeys, retainsdocandtarget_package_name.narrow_context_errors_on_macro_call_in_description— behavioral:full context renders the macro; narrow context errors with "undefined".
narrow_context_allows_doc_in_macro_description— behavioral:{{ doc('my_doc') }}succeeds under the narrow context.Checklist
stated issue
Note
Existing compile errors in
dbt-lexer-*/check_version(ANTLR traitmismatches) prevented
cargo testin my environment. These arepre-existing and unrelated to this change. Tests should pass on a clean tree.