Skip to content

Commit

Permalink
first pass: flags.allow_materialization_overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Apr 16, 2024
1 parent ee74a60 commit 99998a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 16 additions & 1 deletion core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,14 +906,29 @@ 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 (

Check warning on line 918 in core/dbt/contracts/graph/manifest.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/contracts/graph/manifest.py#L918

Added line #L918 was not covered by tests
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,
with_prefix=False,
)
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(
Expand Down
5 changes: 5 additions & 0 deletions core/dbt/contracts/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}


Expand Down

0 comments on commit 99998a5

Please sign in to comment.