Compare commits

...

3 Commits

Author SHA1 Message Date
Gerda Shank
2516e83028 fix test/unit/test_context.py to use postgres profile 2021-04-27 16:08:14 -04:00
Jeremy Cohen
081f30ee2d Include parent adapters in dispatch 2021-04-26 10:28:04 -04:00
Jeremy Cohen
89e4872c21 Add test, expect fail 2021-04-26 10:24:18 -04:00
5 changed files with 63 additions and 10 deletions

View File

@@ -8,7 +8,9 @@ from typing_extensions import Protocol
from dbt import deprecations
from dbt.adapters.base.column import Column
from dbt.adapters.factory import get_adapter, get_adapter_package_names
from dbt.adapters.factory import (
get_adapter, get_adapter_package_names, get_adapter_type_names
)
from dbt.clients import agate_helper
from dbt.clients.jinja import get_rendered, MacroGenerator, MacroStack
from dbt.config import RuntimeConfig, Project
@@ -107,10 +109,11 @@ class BaseDatabaseWrapper:
return self._adapter.commit_if_has_connection()
def _get_adapter_macro_prefixes(self) -> List[str]:
# a future version of this could have plugins automatically call fall
# back to their dependencies' dependencies by using
# `get_adapter_type_names` instead of `[self.config.credentials.type]`
search_prefixes = [self._adapter.type(), 'default']
# order matters for dispatch:
# 1. current adapter
# 2. any parent adapters (dependencies)
# 3. 'default'
search_prefixes = get_adapter_type_names(self.config.credentials.type) + ['default']
return search_prefixes
def dispatch(

View File

@@ -0,0 +1,2 @@
{{ dispatch_to_parent() }}
select 1 as id

View File

@@ -15,8 +15,23 @@
{% endmacro %}
{# there is no no default__dispatch_to_nowhere! #}
{# there is no default__dispatch_to_nowhere! #}
{% macro dispatch_to_nowhere() %}
{% set macro = adapter.dispatch('dispatch_to_nowhere') %}
{{ macro() }}
{% endmacro %}
{% macro dispatch_to_parent() %}
{% set macro = adapter.dispatch('dispatch_to_parent') %}
{{ macro() }}
{% endmacro %}
{% macro default__dispatch_to_parent() %}
{% set msg = 'No default implementation of dispatch_to_parent' %}
{{ exceptions.raise_compiler_error(msg) }}
{% endmacro %}
{% macro postgres__dispatch_to_parent() %}
{{ return('') }}
{% endmacro %}

View File

@@ -95,6 +95,20 @@ class TestAdapterMacroNoDestination(DBTIntegrationTest):
assert "In dispatch: No macro named 'dispatch_to_nowhere' found" in str(exc.value)
class TestDispatchMacroUseParent(DBTIntegrationTest):
@property
def schema(self):
return "test_macros_016"
@property
def models(self):
return "dispatch-inheritance-models"
@use_profile('redshift')
def test_redshift_inherited_macro(self):
self.run_dbt(['run'])
class TestMacroOverrideBuiltin(DBTIntegrationTest):
@property
def schema(self):

View File

@@ -242,6 +242,22 @@ PROFILE_DATA = {
},
}
POSTGRES_PROFILE_DATA = {
'target': 'test',
'quoting': {},
'outputs': {
'test': {
'type': 'postgres',
'host': 'localhost',
'schema': 'analytics',
'user': 'test',
'pass': 'test',
'dbname': 'test',
'port': 1,
}
},
}
PROJECT_DATA = {
'name': 'root',
'version': '0.1',
@@ -368,6 +384,9 @@ def get_include_paths():
def config():
return config_from_parts_or_dicts(PROJECT_DATA, PROFILE_DATA)
@pytest.fixture
def config_postgres():
return config_from_parts_or_dicts(PROJECT_DATA, POSTGRES_PROFILE_DATA)
@pytest.fixture
def manifest_fx(config):
@@ -399,8 +418,8 @@ def redshift_adapter(config, get_adapter):
@pytest.fixture
def postgres_adapter(config, get_adapter):
adapter = postgres.PostgresAdapter(config)
def postgres_adapter(config_postgres, get_adapter):
adapter = postgres.PostgresAdapter(config_postgres)
inject_adapter(adapter, postgres.Plugin)
get_adapter.return_value = adapter
yield adapter
@@ -521,13 +540,13 @@ def test_resolve_specific(config, manifest_extended, redshift_adapter, get_inclu
'dbt', 'root']).macro is rs_macro
def test_resolve_default(config, manifest_extended, postgres_adapter, get_include_paths):
def test_resolve_default(config_postgres, manifest_extended, postgres_adapter, get_include_paths):
dbt_macro = manifest_extended.macros['macro.dbt.default__some_macro']
package_macro = manifest_extended.macros['macro.root.default__some_macro']
ctx = providers.generate_runtime_model(
model=mock_model(),
config=config,
config=config_postgres,
manifest=manifest_extended,
)