diff --git a/core/dbt/context/providers.py b/core/dbt/context/providers.py index 0db9b0c07d0..b62741bf30d 100644 --- a/core/dbt/context/providers.py +++ b/core/dbt/context/providers.py @@ -124,6 +124,24 @@ def _get_adapter_macro_prefixes(self) -> List[str]: search_prefixes = get_adapter_type_names(self._adapter.type()) + ["default"] return search_prefixes + def _get_search_packages(self, macro_namespace: Optional[str] = None): + namespace = macro_namespace + + if namespace is None: + search_packages = [None] + elif isinstance(namespace, str): + search_packages = self._adapter.config.get_macro_search_order(namespace) + if not search_packages and namespace in self._adapter.config.dependencies: + search_packages = [self.config.project_name, namespace] + else: + # Not a string and not None so must be a list + raise CompilationException( + f"In adapter.dispatch, got a list macro_namespace argument " + f'("{macro_namespace}"), but macro_namespace should be None or a string.' + ) + + return search_packages + def dispatch( self, macro_name: str, @@ -145,20 +163,7 @@ def dispatch( if packages is not None: raise macro_invalid_dispatch_arg(macro_name) - namespace = macro_namespace - - if namespace is None: - search_packages = [None] - elif isinstance(namespace, str): - search_packages = self._adapter.config.get_macro_search_order(namespace) - if not search_packages and namespace in self._adapter.config.dependencies: - search_packages = [self.config.project_name, namespace] - else: - # Not a string and not None so must be a list - raise CompilationException( - f"In adapter.dispatch, got a list macro_namespace argument " - f'("{macro_namespace}"), but macro_namespace should be None or a string.' - ) + search_packages = self._get_search_packages(macro_namespace) attempts = []