@@ -115,28 +115,32 @@ def quote_as_configured(self, value: str, component_type: str) -> str:
115115 """Returns the value quoted according to the quote policy."""
116116 return self .quote (value ) if getattr (self .quote_policy , component_type , False ) else value
117117
118- def dispatch (self , name : str , package : t .Optional [str ] = None ) -> t .Callable :
118+ def dispatch (
119+ self ,
120+ macro_name : str ,
121+ macro_namespace : t .Optional [str ] = None ,
122+ ) -> t .Callable :
119123 """Returns a dialect-specific version of a macro with the given name."""
120124 target_type = self .jinja_globals ["target" ]["type" ]
121- macro_suffix = f"__{ name } "
125+ macro_suffix = f"__{ macro_name } "
122126
123127 def _relevance (package_name_pair : t .Tuple [t .Optional [str ], str ]) -> t .Tuple [int , int ]:
124128 """Lower scores more relevant."""
125- macro_package , macro_name = package_name_pair
129+ macro_package , name = package_name_pair
126130
127- package_score = 0 if macro_package == package else 1
131+ package_score = 0 if macro_package == macro_namespace else 1
128132 name_score = 1
129133
130- if macro_name .startswith ("default" ):
134+ if name .startswith ("default" ):
131135 name_score = 2
132- elif macro_name .startswith (target_type ):
136+ elif name .startswith (target_type ):
133137 name_score = 0
134138
135139 return name_score , package_score
136140
137141 jinja_env = self .jinja_macros .build_environment (** self .jinja_globals ).globals
138142 packages_to_check : t .List [t .Optional [str ]] = [
139- package ,
143+ macro_namespace ,
140144 * (k for k in jinja_env if k .startswith ("dbt" )),
141145 ]
142146 candidates = {}
@@ -156,7 +160,7 @@ def _relevance(package_name_pair: t.Tuple[t.Optional[str], str]) -> t.Tuple[int,
156160 sorted_candidates = sorted (candidates , key = _relevance )
157161 return candidates [sorted_candidates [0 ]]
158162
159- raise ConfigError (f"Macro '{ name } ', package '{ package } ' was not found." )
163+ raise ConfigError (f"Macro '{ macro_name } ', package '{ macro_namespace } ' was not found." )
160164
161165 def type (self ) -> str :
162166 return self .project_dialect or ""
0 commit comments