Skip to content

Commit 2e26cd3

Browse files
committed
fix: Fix the issue of incorrect data source connection pool recycling
1 parent 95a7dae commit 2e26cd3

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

backend/apps/db/db.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from common.core.config import settings
3535
import sqlglot
3636
from sqlglot import expressions as exp
37+
from sqlalchemy.pool import NullPool
3738

3839
try:
3940
if os.path.exists(settings.ORACLE_CLIENT_PATH):
@@ -139,24 +140,21 @@ def get_engine(ds: CoreDatasource, timeout: int = 0) -> Engine:
139140
conf.timeout = timeout
140141
if timeout > 0:
141142
conf.timeout = timeout
143+
142144
if equals_ignore_case(ds.type, "pg"):
143145
if conf.dbSchema is not None and conf.dbSchema != "":
144146
engine = create_engine(get_uri(ds),
145147
connect_args={"options": f"-c search_path={urllib.parse.quote(conf.dbSchema)}",
146-
"connect_timeout": conf.timeout},
147-
pool_timeout=conf.timeout)
148+
"connect_timeout": conf.timeout}, poolclass=NullPool)
148149
else:
149-
engine = create_engine(get_uri(ds),
150-
connect_args={"connect_timeout": conf.timeout},
151-
pool_timeout=conf.timeout)
150+
engine = create_engine(get_uri(ds), connect_args={"connect_timeout": conf.timeout}, poolclass=NullPool)
152151
elif equals_ignore_case(ds.type, 'sqlServer'):
153152
engine = create_engine('mssql+pymssql://', creator=lambda: get_origin_connect(ds.type, conf),
154-
pool_timeout=conf.timeout)
153+
poolclass=NullPool)
155154
elif equals_ignore_case(ds.type, 'oracle'):
156-
engine = create_engine(get_uri(ds),
157-
pool_timeout=conf.timeout)
155+
engine = create_engine(get_uri(ds), poolclass=NullPool)
158156
else: # mysql, ck
159-
engine = create_engine(get_uri(ds), connect_args={"connect_timeout": conf.timeout}, pool_timeout=conf.timeout)
157+
engine = create_engine(get_uri(ds), connect_args={"connect_timeout": conf.timeout}, poolclass=NullPool)
160158
return engine
161159

162160

0 commit comments

Comments
 (0)