Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional should_release_connection parameter to connection_named method #247

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading