Skip to content

Commit 5889c0b

Browse files
author
kadhikari
committed
Replace connect and close by a optimized select
1 parent 6f15113 commit 5889c0b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

source/jormungandr/jormungandr/utils.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,8 @@ def can_connect_to_database():
690690
if hasattr(g, 'can_connect_to_database'):
691691
return g.can_connect_to_database
692692
try:
693-
engine = models.db.engine
694-
connection = engine.connect()
695-
connection.close()
693+
# Instead of creating a new connection to the database, better to test select on the smallest table.
694+
models.db.engine.scalar('select version_num from alembic_version;')
696695
g.can_connect_to_database = True
697696
except Exception:
698697
logging.getLogger(__name__).exception('Connection to database has failed')

0 commit comments

Comments
 (0)