From 17545d59d88a70836799552f53fc850a1b6d6caf Mon Sep 17 00:00:00 2001 From: funilrys Date: Tue, 19 Dec 2023 19:38:02 +0100 Subject: [PATCH] Add pre_ping. Indeed, before this patch, we weren't retrying to reconnect properly. This patch fixes the issue by using the pre_ping function of sqlalchemy. This patch fixes #346. Contributors: * @spirillen --- PyFunceble/database/session.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/PyFunceble/database/session.py b/PyFunceble/database/session.py index 9a3c8f5a..b8fc078a 100644 --- a/PyFunceble/database/session.py +++ b/PyFunceble/database/session.py @@ -150,6 +150,7 @@ def init_db_sessions(self) -> "DBSession": autoflush=True, autocommit=False, expire_on_commit=False, + pre_ping=True, ) return self @@ -180,7 +181,11 @@ def get_new_session(self) -> sqlalchemy.orm.sessionmaker: ) return sqlalchemy.orm.sessionmaker( - bind=engine, autoflush=True, autocommit=False, expire_on_commit=False + bind=engine, + autoflush=True, + autocommit=False, + expire_on_commit=False, + pre_ping=True, ) @execute_if_authorized(None) @@ -195,7 +200,11 @@ def get_new_pool_session(self) -> sqlalchemy.orm.sessionmaker: ) return sqlalchemy.orm.sessionmaker( - bind=engine, autoflush=True, autocommit=False, expire_on_commit=False + bind=engine, + autoflush=True, + autocommit=False, + expire_on_commit=False, + pre_ping=True, ) def close(self) -> "DBSession":