Skip to content

Commit b3e9283

Browse files
author
Sebastian
committed
Fix connect_args
1 parent 257e87a commit b3e9283

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

mcpgateway/db.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@
4949
from mcpgateway.config import settings
5050
from mcpgateway.types import ResourceContent
5151

52+
base_connect_args = {}
53+
# Add the SQLite-only flag when appropriate
54+
if settings.database_url.startswith("sqlite"):
55+
base_connect_args["check_same_thread"] = False
56+
elif settings.database_url.startswith("postgres"):
57+
base_connect_args = {
58+
"keepalives": 1,
59+
"keepalives_idle": 30,
60+
"keepalives_interval": 5,
61+
"keepalives_count": 5,
62+
}
63+
5264
# Create SQLAlchemy engine with connection pooling
5365
engine = create_engine(
5466
settings.database_url,
@@ -57,13 +69,7 @@
5769
max_overflow=settings.db_max_overflow,
5870
pool_timeout=settings.db_pool_timeout,
5971
pool_recycle=settings.db_pool_recycle,
60-
connect_args = {
61-
"keepalives": 1,
62-
"keepalives_idle": 30,
63-
"keepalives_interval": 5,
64-
"keepalives_count": 5,
65-
}
66-
# connect_args={"check_same_thread": False} if settings.database_url.startswith("sqlite") else {},
72+
connect_args=base_connect_args
6773
)
6874

6975
# Session factory

0 commit comments

Comments
 (0)