3535from dbt .parser .sql import SqlBlockParser , SqlMacroParser
3636from dbt .task .sql import SqlCompileRunner
3737from dbt .tracking import disable_tracking
38+ from dbt_common .clients .system import get_env
39+ from dbt_common .context import set_invocation_context
3840
3941disable_tracking ()
42+ set_invocation_context (get_env ())
4043
4144__all__ = ["DbtProject" , "DbtConfiguration" , "ExecutionResult" , "CompilationResult" ]
4245
@@ -198,17 +201,18 @@ def _initialize_adapter(self) -> None:
198201 raise RuntimeError ("Runtime config not available" )
199202
200203 adapter_cls = get_adapter_class_by_name (self ._runtime_config .credentials .type )
201- self ._adapter = t .cast (BaseAdapter , adapter_cls (self ._runtime_config , get_mp_context ())) # pyright: ignore[reportInvalidCast]
204+ try :
205+ self ._adapter = t .cast (BaseAdapter , adapter_cls (self ._runtime_config , get_mp_context ())) # pyright: ignore[reportInvalidCast,reportCallIssue]
206+ except ValueError :
207+ self ._adapter = t .cast (BaseAdapter , adapter_cls (self ._runtime_config )) # pyright: ignore[reportInvalidCast]
202208
203- # Verify connection
204209 with self ._adapter .connection_named ("master" ):
205210 self ._adapter .debug_query ()
206211
207212 logger .debug (f"Initialized adapter for { self .project_name } " )
208213
209214 def _parse_project (self ) -> None :
210215 """Parse the dbt project and load manifest."""
211- # Set dbt flags
212216 set_from_args (
213217 argparse .Namespace (
214218 target = self .config .target ,
@@ -223,7 +227,6 @@ def _parse_project(self) -> None:
223227 )
224228
225229 with self ._manifest_lock :
226- # Load runtime config
227230 self ._runtime_config = RuntimeConfig .from_args (
228231 argparse .Namespace (
229232 target = self .config .target ,
@@ -234,13 +237,12 @@ def _parse_project(self) -> None:
234237 )
235238 )
236239
237- # Initialize adapter
238240 self ._initialize_adapter ()
239241
240- # Load manifest
241242 manifest_loader = ManifestLoader (
242243 self ._runtime_config ,
243- self ._runtime_config .dependencies or {},
244+ self ._runtime_config .load_dependencies (),
245+ self .adapter .connections .set_query_header , # pyright: ignore[reportArgumentType]
244246 )
245247 self ._manifest = manifest_loader .load ()
246248
0 commit comments