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

Fix adapter macro namespacing (#2548) #2590

Merged
merged 6 commits into from
Jul 1, 2020

Conversation

beckjake
Copy link
Contributor

@beckjake beckjake commented Jun 25, 2020

resolves #2548

Description

Fix adapter macros so they can override core (and one another) in consistent ways.

Generally, macros from plugins that aren't actively in use are no longer available, and macros follow a name resolution hieirarchy within dbt: dbt-global-project macros have a lower precedence than dependency plugins have a lower precedence than the current plugin. If the adapter type is unknown, dbt loads all the plugins it knows about in an undefined order, except that the internal global project is guaranteed to have the lowest priority.

To make this effective without doing tons of imports inside functions/methods, I had to refactor a bit. Some functions moved out of dbt.utils to remove its dependencies, and some base type definitions moved from adapters into contracts. I also (finally) moved node runners into their non-rpc tasks, which allowed me to move some common logic into dbt.task, and consolidated dbt.ui.* into a single dbt.ui.

Most of these changes are rewritten imports and files moved. The changes that require the most attention are the changes to adapter/factory.py (plugin loading, path determination) and context/configured.py (macro resolution)

This does not convert adapter_macro into a python function, but I think it should make it unnecessary.

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, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt next" section.

Jacob Beck added 4 commits June 25, 2020 09:59
adapter_types -> plugins
Use factory.packages instead of global PACKAGES
consolidate dbt.ui, move non-rpc node_runners into their tasks
move parse_cli_vars into config.utils
get rid of logger/exceptions requirements in dbt.utils
Moved some relation logic out of adapters and into contracts
Fixed a typo in a type name
Fixed an issue where tests could fail based on color settings
Fixed the type analysis for adapter plugins/factory
Swapped more concrete tyeps out for protocols
Finally removed PACKAGES global
Added unit tests
@cla-bot cla-bot bot added the cla:yes label Jun 25, 2020
@beckjake beckjake marked this pull request as ready for review June 25, 2020 16:25
Copy link
Contributor

@kwigley kwigley left a comment

Choose a reason for hiding this comment

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

Nice, the ordering and hierarchy logic looks to me. Approved on my end

core/dbt/adapters/factory.py Outdated Show resolved Hide resolved
Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

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

I didn't spend too much time looking at the diff, so I'll defer to @kwigley on that front. I did test this out locally, and everything appeared to work as expected. LGTM!

@beckjake
Copy link
Contributor Author

beckjake commented Jul 1, 2020

It's not clear to me why I have to do this, but: @cla-bot check

@cla-bot
Copy link

cla-bot bot commented Jul 1, 2020

The cla-bot has been summoned, and re-checked this pull request!

@beckjake beckjake merged commit 3af8a22 into dev/marian-anderson Jul 1, 2020
@kwigley kwigley deleted the fix/adapter-macro-namespacing branch February 5, 2021 17:19
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.

Unable to override macros in adapter
3 participants