Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Fix FATAL: sorry, too many clients already
Browse files Browse the repository at this point in the history
Dispose the SQLAlchemy engine object after use within
`PostgresConnector`.
amotl committed Dec 19, 2023
1 parent 2eede7e commit 5a70027
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions target_postgres/connector.py
Original file line number Diff line number Diff line change
@@ -180,8 +180,10 @@ def copy_table_structure(

@contextmanager
def _connect(self) -> t.Iterator[sqlalchemy.engine.Connection]:
with self._engine.connect().execution_options() as conn:
engine = self._engine
with engine.connect().execution_options() as conn:
yield conn
engine.dispose()

def drop_table(
self, table: sqlalchemy.Table, connection: sqlalchemy.engine.Connection
@@ -800,9 +802,7 @@ def column_exists( # type: ignore[override]
)

def __del__(self):
"""
Dispose underlying SQLAlchemy engine object.
"""
"""Dispose underlying SQLAlchemy engine object."""
if self._cached_engine is not None:
self._cached_engine.dispose()

0 comments on commit 5a70027

Please sign in to comment.