Skip to content

Commit

Permalink
Add optional should_release_connection parameter to `connection_nam…
Browse files Browse the repository at this point in the history
…ed` method (#247)
  • Loading branch information
aranke authored Jun 26, 2024
1 parent e964302 commit 0739850
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240624-161108.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Add optional release_connection parameter to connection_named method
time: 2024-06-24T16:11:08.773419+01:00
custom:
Author: aranke
Issue: "247"
8 changes: 6 additions & 2 deletions dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,18 @@ def nice_connection_name(self) -> str:
return conn.name

@contextmanager
def connection_named(self, name: str, query_header_context: Any = None) -> Iterator[None]:
def connection_named(
self, name: str, query_header_context: Any = None, should_release_connection=True
) -> Iterator[None]:
try:
if self.connections.query_header is not None:
self.connections.query_header.set(name, query_header_context)
self.acquire_connection(name)
yield
finally:
self.release_connection()
if should_release_connection:
self.release_connection()

if self.connections.query_header is not None:
self.connections.query_header.reset()

Expand Down

0 comments on commit 0739850

Please sign in to comment.