From 99998a597c75d71f85b85202e31de6cff984249e Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Mon, 15 Apr 2024 23:19:38 -0700 Subject: [PATCH] first pass: flags.allow_materialization_overrides --- core/dbt/contracts/graph/manifest.py | 17 ++++++++++++++++- core/dbt/contracts/project.py | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/dbt/contracts/graph/manifest.py b/core/dbt/contracts/graph/manifest.py index 852f4dce724..15834dd2e59 100644 --- a/core/dbt/contracts/graph/manifest.py +++ b/core/dbt/contracts/graph/manifest.py @@ -906,6 +906,21 @@ def _materialization_candidates_for( adapter_type: str, specificity: int, ) -> CandidateList: + + # Do not include imported macros in materialization macro candidates + def filter(candidate: MacroCandidate) -> bool: + flags = get_flags() + # legacy behaviour - allow materialization overrides from packages + if flags.allow_materialization_overrides is None: + # TODO: fire deprecation event + return True + else: + return ( + candidate.macro.package_name in flags.allow_materialization_overrides + if candidate.locality == Locality.Imported + else True + ) + full_name = dbt_common.utils.get_materialization_macro_name( materialization_name=materialization_name, adapter_type=adapter_type, @@ -913,7 +928,7 @@ def _materialization_candidates_for( ) return CandidateList( MaterializationCandidate.from_macro(m, specificity) - for m in self._find_macros_by_name(full_name, project_name) + for m in self._find_macros_by_name(full_name, project_name, filter=filter) ) def find_materialization_macro_by_name( diff --git a/core/dbt/contracts/project.py b/core/dbt/contracts/project.py index 46c9742952f..4616fd9e2d7 100644 --- a/core/dbt/contracts/project.py +++ b/core/dbt/contracts/project.py @@ -297,6 +297,10 @@ def validate(cls, data): @dataclass class ProjectFlags(ExtensibleDbtClassMixin): allow_spaces_in_model_names: Optional[bool] = True + # None => default, allow from all (default behaviour) + # ["dbt_utils"] => only allow from these packages + # [] => allow from none, will be new default behaviour + allow_materialization_overrides: Optional[List[str]] = None cache_selected_only: Optional[bool] = None debug: Optional[bool] = None fail_fast: Optional[bool] = None @@ -324,6 +328,7 @@ def project_only_flags(self) -> Dict[str, Any]: return { "source_freshness_run_project_hooks": self.source_freshness_run_project_hooks, "allow_spaces_in_model_names": self.allow_spaces_in_model_names, + "allow_materialization_overrides": self.allow_materialization_overrides, }