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

Fix premature connection closure #1525

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions datacube/drivers/postgis/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,13 @@ def in_transaction(self):
return self._connection.in_transaction()

def begin(self):
self._connection.execution_options(isolation_level="REPEATABLE READ")
# execution_options does not modify connection in-place in sqlalchemy 1.4
self._connection = self._connection.execution_options(isolation_level="REPEATABLE READ")
self._sqla_txn = self._connection.begin()

def _end_transaction(self):
self._sqla_txn = None
self._connection.execution_options(isolation_level="AUTOCOMMIT")
self._connection = self._connection.execution_options(isolation_level="AUTOCOMMIT")

def commit(self):
self._sqla_txn.commit()
Expand Down
1 change: 0 additions & 1 deletion datacube/drivers/postgis/_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ def _connect(self):
"""
with self._engine.connect() as connection:
try:
connection.execution_options(isolation_level="AUTOCOMMIT")
yield _api.PostgisDbAPI(self, connection)
finally:
connection.close()
Expand Down
5 changes: 3 additions & 2 deletions datacube/drivers/postgres/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,13 @@ def in_transaction(self):
return self._connection.in_transaction()

def begin(self):
self._connection.execution_options(isolation_level="REPEATABLE READ")
# execution_options does not modify connection in-place in sqlalchemy 1.4
self._connection = self._connection.execution_options(isolation_level="REPEATABLE READ")
self._sqla_txn = self._connection.begin()

def _end_transaction(self):
self._sqla_txn = None
self._connection.execution_options(isolation_level="AUTOCOMMIT")
self._connection = self._connection.execution_options(isolation_level="AUTOCOMMIT")

def commit(self):
self._sqla_txn.commit()
Expand Down
1 change: 0 additions & 1 deletion datacube/drivers/postgres/_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ def _connect(self):
"""
with self._engine.connect() as connection:
try:
connection.execution_options(isolation_level="AUTOCOMMIT")
yield _api.PostgresDbAPI(connection)
finally:
connection.close()
Expand Down
Loading