Skip to content

Commit

Permalink
Add pre_ping.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
funilrys committed Dec 19, 2023
1 parent 912acc7 commit 17545d5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions PyFunceble/database/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def init_db_sessions(self) -> "DBSession":
autoflush=True,
autocommit=False,
expire_on_commit=False,
pre_ping=True,
)

return self
Expand Down Expand Up @@ -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)
Expand All @@ -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":
Expand Down

0 comments on commit 17545d5

Please # to comment.