Skip to content

prevent scoped_session closing the connection when there are active sessions #1786

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions backend/dataall/base/db/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from dataall.base.db import Base
from dataall.base.db.dbconfig import DbConfig
from dataall.base.utils import Parameter
from dataall.base.aws.sts import SessionHelper

try:
from urllib import quote_plus, unquote_plus
Expand Down Expand Up @@ -41,6 +40,7 @@ def __init__(self, dbconfig: DbConfig):

self.sessions = {}
self._session = None
self._active_sessions = 0

def session(self):
if self._session is None:
Expand All @@ -52,13 +52,17 @@ def session(self):
def scoped_session(self):
s = self.session()
try:
self._active_sessions += 1
yield s
s.commit()
except Exception as e:
s.rollback()
raise e
finally:
s.close()
self._active_sessions -= 1
if self._active_sessions == 0:
s.close()
self._session = None

def dispose(self):
self.engine.dispose()
Expand Down
Loading