@@ -192,8 +192,9 @@ def _ensure_connection(f: t.Callable[P, T]) -> t.Callable[P, T]:
192192 @functools .wraps (f )
193193 def wrapper (* args : P .args , ** kwargs : P .kwargs ) -> T :
194194 self = t .cast (DbtProject , args [0 ])
195- _ = self .adapter .connections .set_connection_name ()
196- return f (* args , ** kwargs )
195+ is_duckdb = self .adapter .connections .TYPE == "duckdb"
196+ with self .adapter .connection_named (f .__name__ , should_release_connection = is_duckdb ):
197+ return f (* args , ** kwargs )
197198
198199 return wrapper
199200
@@ -872,6 +873,7 @@ def _lint(node: ManifestNode) -> list[LintingRecord]:
872873 all_records : list [LintingRecord ] = []
873874 for records in self .pool .map (_lint , self .manifest .nodes .values ()):
874875 all_records .extend (records )
876+ self .adapter .cleanup_connections ()
875877
876878 return all_records
877879 elif isinstance (sql , str ):
@@ -935,7 +937,9 @@ def _format(node: ManifestNode) -> bool:
935937 success = False
936938 return success
937939
938- return all (res for res in self .pool .map (_format , self .manifest .nodes .values ())), None
940+ result = all (res for res in self .pool .map (_format , self .manifest .nodes .values ())), None
941+ self .adapter .cleanup_connections ()
942+ return result
939943 if isinstance (sql , str ):
940944 logger .info (f"Formatting SQL string: { sql [:100 ]} " )
941945 result = lint .lint_string_wrapped (sql , fname = "stdin" , fix = True )
0 commit comments