Skip to content

Commit c365f0a

Browse files
committed
prevent scoped_session closing the connection when there are active sessions
1 parent c36d337 commit c365f0a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

backend/dataall/base/db/connection.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from dataall.base.db import Base
1212
from dataall.base.db.dbconfig import DbConfig
1313
from dataall.base.utils import Parameter
14-
from dataall.base.aws.sts import SessionHelper
1514

1615
try:
1716
from urllib import quote_plus, unquote_plus
@@ -41,6 +40,7 @@ def __init__(self, dbconfig: DbConfig):
4140

4241
self.sessions = {}
4342
self._session = None
43+
self._active_sessions = 0
4444

4545
def session(self):
4646
if self._session is None:
@@ -52,13 +52,17 @@ def session(self):
5252
def scoped_session(self):
5353
s = self.session()
5454
try:
55+
self._active_sessions += 1
5556
yield s
5657
s.commit()
5758
except Exception as e:
5859
s.rollback()
5960
raise e
6061
finally:
61-
s.close()
62+
self._active_sessions -= 1
63+
if self._active_sessions == 0:
64+
s.close()
65+
self._session = None
6266

6367
def dispose(self):
6468
self.engine.dispose()

0 commit comments

Comments
 (0)