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

deprecate materialization overrides from imported packages #9971

Merged
merged 6 commits into from
Apr 22, 2024

Conversation

MichelleArk
Copy link
Contributor

@MichelleArk MichelleArk commented Apr 17, 2024

resolves #9981

Problem

We are deprecating the ability for installed packages to override built-in materializations without explicit opt-in from the user.

Users should still be able to wrap the built-in materialization in their root project to avoid this deprecation warning. e.g:

{% materialization view, default %}
 {{ return(my_cool_package.materialization_view_default()) }}
{% endmaterialization %}

Solution

  • When the materializations are resolved at execution-time, if the chosen materialization has a possible 'global' (core / built-in) candidate, raise a deprecation warning indicating that an installed package has won over a built-in one.
  • This would be overly-complex to do at parse-time (would need to link materializations together based on their name, and reuse (if possible) or reimplement a bunch of code that is run during execution at parse-time. This doesn't seem worth it for something that will become legacy behaviour.
    • However, it should be more straightforward to raise a warning at parse-time for regular macros (in a separate issue / follow-on PR)

🎩


Invoking dbt with ['run']
20:23:19  Running with dbt=1.8.0-b2
20:23:19  Registered adapter: postgres=1.8.0-b4
20:23:19  Unable to do partial parsing because saved manifest not found. Starting full parse.
20:23:19  Found 1 model, 412 macros
20:23:19  
20:23:20  Concurrency: 4 threads (target='default')
20:23:20  
20:23:20  1 of 1 START sql view model test17134717990861067406_test_custom_materialization.model  [RUN]
20:23:20  [WARNING]: Installed package 'view_default_override' is overriding the
built-in materialization 'view'. Overrides of built-in materializations from
installed packages will be deprecated in future versions of dbt.
20:23:20  1 of 1 ERROR creating sql view model test17134717990861067406_test_custom_materialization.model  [ERROR in 0.01s]
20:23:20  
20:23:20  Finished running 1 view model in 0 hours 0 minutes and 0.49 seconds (0.49s).
20:23:20  
20:23:20  Completed with 1 error and 0 warnings:
20:23:20  
20:23:20    Compilation Error in model model (models/model.sql)
  intentionally raising an error in the default view materialization
  
  > in macro materialization_view_default (macros/default_view.sql)
  > called by model model (models/model.sql)

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 Apr 17, 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 Apr 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.12%. Comparing base (2edd5b3) to head (14dbd00).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9971      +/-   ##
==========================================
- Coverage   88.12%   88.12%   -0.01%     
==========================================
  Files         180      181       +1     
  Lines       22578    22614      +36     
==========================================
+ Hits        19897    19928      +31     
- Misses       2681     2686       +5     
Flag Coverage Δ
integration 85.44% <100.00%> (+<0.01%) ⬆️
unit 62.21% <100.00%> (+0.12%) ⬆️

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 marked this pull request as ready for review April 18, 2024 21:25
@MichelleArk MichelleArk requested a review from a team as a code owner April 18, 2024 21:25
return "D016"

def message(self) -> str:
description = f"Installed package '{self.package_name}' is overriding the built-in materialization '{self.materialization_name}'. Overrides of built-in materializations from installed packages will be deprecated in future versions of dbt."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: link to docs on workaround before merging

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message looks good!

I figure we can link to the docs for the behavior change flag, which will go here: https://docs.getdbt.com/reference/global-configs/legacy-behaviors#source_freshness_run_project_hooks

Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichelleArk Nice precise work! I'm satisfied with raising this warning at execution time. It means that developers will only see this when running/building the specific models, but given that this is for builtin materializations (view/table/incremental/mv), it shouldn't be searching for needle in haystack.

Confirmed with quick local testing that we don't raise this deprecation warning if:

  • a built-in materailization has an override defined within the adapter (e.g. dbt-snowflake's view)
  • the package-defined materialization has a different name (e.g. myview) that doesn't collide with a built-in materialization's name

@@ -930,7 +935,24 @@ def find_materialization_macro_by_name(
for specificity, atype in enumerate(self._get_parent_adapter_types(adapter_type))
)
)
return candidates.last()
core_candidates = [
candidate for candidate in candidates if candidate.locality == Locality.Core
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return "D016"

def message(self) -> str:
description = f"Installed package '{self.package_name}' is overriding the built-in materialization '{self.materialization_name}'. Overrides of built-in materializations from installed packages will be deprecated in future versions of dbt."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message looks good!

I figure we can link to the docs for the behavior change flag, which will go here: https://docs.getdbt.com/reference/global-configs/legacy-behaviors#source_freshness_run_project_hooks

core/dbt/deprecations.py Show resolved Hide resolved
@MichelleArk MichelleArk merged commit 0290cf7 into main Apr 22, 2024
62 checks passed
@MichelleArk MichelleArk deleted the arky/deprecate-package-materializations branch April 22, 2024 15:08
Copy link
Contributor

The backport to 1.6.latest failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.6.latest 1.6.latest
# Navigate to the new working tree
cd .worktrees/backport-1.6.latest
# Create a new branch
git switch --create backport-9971-to-1.6.latest
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 0290cf7dd0f7c386b802116d4c312477c4af8c02
# Push it to GitHub
git push --set-upstream origin backport-9971-to-1.6.latest
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.6.latest

Then, create a pull request where the base branch is 1.6.latest and the compare/head branch is backport-9971-to-1.6.latest.

Copy link
Contributor

The backport to 1.7.latest failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.7.latest 1.7.latest
# Navigate to the new working tree
cd .worktrees/backport-1.7.latest
# Create a new branch
git switch --create backport-9971-to-1.7.latest
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 0290cf7dd0f7c386b802116d4c312477c4af8c02
# Push it to GitHub
git push --set-upstream origin backport-9971-to-1.7.latest
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.7.latest

Then, create a pull request where the base branch is 1.7.latest and the compare/head branch is backport-9971-to-1.7.latest.

@MichelleArk
Copy link
Contributor Author

(WIP) Manual backports:
1.6: #10008
1.7: #9998

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raise deprecation warning if installed package overrides built-in materialization
3 participants