Skip to content
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

Unit Testing: Support overriding macros in packages #9626

Merged
merged 6 commits into from
Mar 15, 2024

Conversation

MichelleArk
Copy link
Contributor

@MichelleArk MichelleArk commented Feb 22, 2024

resolves #9624

Problem

It's not currently possible to override a macro that is referenced by its packaged-namespaced syntax. (e.g. dbt.current_timestamp, or my_package.my_macro). Only global references are overridden as expected.

Solution

Support overriding macros at the package-namespaced level, in addition to the global level (if it is a global macro) by:

  • iterating over the provided overrides, and splitting them into global and package-namespaced macros
  • apply package-namespaced overrides
    • if the package is dbt, also propagate the override to the global level
  • apply global overrides
    • this ensures global overrides take precedence over package-namespacing if both override levels are provided (not sure why anyone would do this). confirmed with @graciegoheen that this is the desired behaviour
    • if the global override is a dbt macro, override it at the dbt package-level so that the dbt.my_macro reference is overriden as expected!

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX
  • This PR includes type annotations for new and modified functions

@cla-bot cla-bot bot added the cla:yes label Feb 22, 2024
Copy link
Contributor

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.

Copy link

codecov bot commented Feb 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.13%. Comparing base (d65bae5) to head (d51224b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9626      +/-   ##
==========================================
- Coverage   88.17%   88.13%   -0.04%     
==========================================
  Files         178      178              
  Lines       22460    22479      +19     
==========================================
+ Hits        19803    19811       +8     
- Misses       2657     2668      +11     
Flag Coverage Δ
integration 85.51% <100.00%> (-0.12%) ⬇️
unit 62.54% <100.00%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MichelleArk MichelleArk force-pushed the unit-test-macro-overrides-packages branch from 2d4cc8a to 075ed36 Compare March 15, 2024 18:54
@MichelleArk MichelleArk changed the title first pass: support macro overrides in packages Unit Testing: Support overriding macros in packages Mar 15, 2024
@MichelleArk MichelleArk marked this pull request as ready for review March 15, 2024 19:05
@MichelleArk MichelleArk requested a review from a team as a code owner March 15, 2024 19:05
@MichelleArk MichelleArk requested a review from gshank March 15, 2024 19:05
@MichelleArk MichelleArk merged commit c501d71 into main Mar 15, 2024
58 checks passed
@MichelleArk MichelleArk deleted the unit-test-macro-overrides-packages branch March 15, 2024 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] can't override namespaced macros for unit testing
2 participants