-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[CT-965] [Bug] Variable scoping ignored for macros #5587
Comments
hello @NiallRees, thanks for opening! apologies for the unusually long triage time on this one. what you're noticing is expected behavior that we don't intend on changing, so I'm going to close this as won't fix. hopefully the explanation below is helpful, and I have logged an issue to improve the docs here
macros are resolved within the context of the model calling them (and its project), not the macro's project. you should be able to fix what you're experience by defining the environment variable in the model's project. can you try that out and let us know if you're still experiencing issues? |
docs issue: dbt-labs/docs.getdbt.com#1928 |
* bump version * extraneous comma * prepare for deprecations * remove namespacing of variables dbt-labs/dbt-core#5587 * Update fct_student_assessment.sql (#18)
* bump version * bugfix extraneous comma * prepare for dbt macro deprecations * remove namespacing of variables. see: dbt-labs/dbt-core#5587 * add identifiers to fct_student_assessment.sql (#18)
Is this a new bug in dbt-core?
Current Behavior
I'm developing the dbt_artifacts package, and have an integration test project which installs the dbt_artifacts package using a local: file system reference:
Within the integration test project's dbt_project.yml, I've defined these variables, the idea being that anything under the dbt_artifacts key is scoped only to the dbt_artifacts package.
If I use
{{ var('env_vars') }}
in one of dbt_artifacts' models, the model renders that value correctly as['TEST_ENV_VAR_1']
.However, if I add
{{ var('env_vars') }}
to a macro (upload_invocations) in the dbt_artifacts package which is called from the on-run-end hook of the integration test project:I get an error:
Expected Behavior
From reading the docs here, I would expect the variable used in the package's macro to render identically to how it does in the package's model. Instead, it seems that I cannot scope a variable to the package if I want to reference it within a macro.
Steps To Reproduce
See above
Relevant log output
Environment
Which database adapter are you using with dbt?
snowflake
Additional Context
No response
The text was updated successfully, but these errors were encountered: