Skip to content

fix: use restricted Jinja context for macro property resolution#1577

Closed
yxshwanth wants to merge 1 commit intodbt-labs:mainfrom
yxshwanth:fix/restrict-macro-properties-resolve-context
Closed

fix: use restricted Jinja context for macro property resolution#1577
yxshwanth wants to merge 1 commit intodbt-labs:mainfrom
yxshwanth:fix/restrict-macro-properties-resolve-context

Conversation

@yxshwanth
Copy link
Copy Markdown

Problem

Resolves #1576

Jinja expressions inside a macro's description: field in schema YAML are
evaluated at parse time using the full project macro context. This causes
{{ cents_to_dollars('price_cents') }} to silently render to
price_cents / 100.0 in manifest.json. In dbt Core, the same expression
causes a parse error ("undefined"), which is the correct behavior.

Solution

Add build_macro_properties_resolve_context in resolve_context.rs, which
constructs the same Jinja environment as build_resolve_context but passes
no namespace_keys — so no DbtNamespace entries (project/package macros)
are injected. This restricted context is threaded through two call sites:
resolve_properties and apply_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 — matching
dbt Core behavior.

Tests

Three tests in resolve_context.rs under #[cfg(test)]:

  1. macro_properties_context_omits_macro_namespace_keys — structural:
    narrow context has no dbt/local_pkg keys, retains doc and
    target_package_name.
  2. narrow_context_errors_on_macro_call_in_description — behavioral:
    full context renders the macro; narrow context errors with "undefined".
  3. narrow_context_allows_doc_in_macro_description — behavioral:
    {{ doc('my_doc') }} succeeds under the narrow context.
cargo test -p dbt-jinja-utils macro_properties_context
cargo test -p dbt-jinja-utils narrow_context
cargo check -p dbt-parser

Checklist

  • I have signed the CLA
  • I have run this code in development and it appears to resolve the
    stated issue
  • This PR includes tests
  • I have added e changelog entry

Note

Existing compile errors in dbt-lexer-* / check_version (ANTLR trait
mismatches) prevented cargo test in my environment. These are
pre-existing and unrelated to this change. Tests should pass on a clean tree.

@yxshwanth yxshwanth requested a review from a team as a code owner April 13, 2026 06:05
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 13, 2026

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 is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@github-actions
Copy link
Copy Markdown

This repository enforces signed commits. Please sign your commits by following the docs here.

@yxshwanth yxshwanth force-pushed the fix/restrict-macro-properties-resolve-context branch from 2512548 to a296c04 Compare April 13, 2026 06:07
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 13, 2026

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.
@yxshwanth yxshwanth force-pushed the fix/restrict-macro-properties-resolve-context branch from a296c04 to 73e1c3a Compare April 13, 2026 06:08
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented Apr 13, 2026

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

@yxshwanth yxshwanth closed this Apr 13, 2026
@yxshwanth yxshwanth deleted the fix/restrict-macro-properties-resolve-context branch April 13, 2026 06:09
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.

[BUG] Fusion uses different Jinja context evaluating description fields than Core

1 participant