-
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
Enable calling a macro in a pre- or post-hook config in properties.yml
#10603
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10603 +/- ##
==========================================
- Coverage 88.92% 88.91% -0.02%
==========================================
Files 180 180
Lines 22760 22762 +2
==========================================
- Hits 20240 20239 -1
- Misses 2520 2523 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide. |
This was referenced Aug 26, 2024
Closed
gshank
approved these changes
Aug 27, 2024
dbeatty10
added a commit
that referenced
this pull request
Aug 27, 2024
…ml` (#10603) (#10620) * Tests for calling a macro in a pre- or post-hook config in properties.yml * Late render pre- and post-hooks configs in properties / schema YAML files * Changelog entry (cherry picked from commit 2218140) Co-authored-by: Doug Beatty <[email protected]>
mirnawong1
added a commit
to dbt-labs/docs.getdbt.com
that referenced
this pull request
Sep 5, 2024
[Preview: Calling a macro in a hook](https://docs-getdbt-com-git-dbeatty10-patch-2-dbt-labs.vercel.app/docs/build/hooks-operations#calling-a-macro-in-a-hook) [Preview: pre-hook & post-hook ](https://docs-getdbt-com-git-dbeatty10-patch-2-dbt-labs.vercel.app/reference/resource-configs/pre-hook-post-hook) ## What are you changing in this pull request and why? We have a couple concrete examples of calling a macro in a hook (like [here](https://docs.getdbt.com/reference/project-configs/on-run-start-on-run-end#call-a-macro-to-grant-privileges) and [here](https://docs.getdbt.com/reference/resource-configs/pre-hook-post-hook#apache-spark-analyze-tables-after-creation)). But we don't currently have any co-located canonical examples of the different locations where hooks can be configured: 1. SQL model config 1. `properties.yml` \* 1. `dbt_project.yml` \* Calling a macro in a hook within a properties YAML file was fixed in v1.8+ by dbt-labs/dbt-core#10603. ## Other pages to review Once dbt-labs/dbt-core#7128 is resolved, we should also review these pages to ensure they include examples of configs across `dbt_project` YAML files, properties YAML files, and node-level config in SQL files: - https://docs.getdbt.com/reference/resource-configs/pre-hook-post-hook - https://docs.getdbt.com/reference/model-configs#apply-configurations-to-one-model-only - https://docs.getdbt.com/reference/seed-configs#apply-the-schema-configuration-to-one-seed-only ## Additional context Inspired by dbt-labs/dbt-core#10522 ## Checklist - [x] Review the [Content style guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md) so my content adheres to these guidelines. --------- Co-authored-by: Mirna Wong <[email protected]>
Open
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #7128
Also reported in #10602 and #9482.
Problem
Because pre- and post-hooks within
properties.yml
files are not late-rendered for models, seeds, etc., references to{{ this }}
, macros, etc. don't work:properties.yml
The example seed post-hook above is just a single value (not a list), whereas the example model pre-hook is a list. Both are valid! The former contains Jinja for the
this
context variable, and the latter contains a Jinja macro.Solution
Late-render pre- and post-hooks within properties / schema YAML files (like they are for
dbt_project.yml
)🎩 Testing
Added two new tests to handle the difference between a hook that is just a string vs. a list of hooks:
TestPrePostModelHooksWithMacros
TestPrePostModelHooksListWithMacros
❌ ❌ The two new tests failed (as we hoped) prior to the fix:
✅ ✅ And both succeed after the fix in fbe20e9.
I also manually checked both the seeds and models examples listed above.
Checklist