Skip to content

Commit

Permalink
rollback before closing active session
Browse files Browse the repository at this point in the history
  • Loading branch information
ahdamin committed Sep 24, 2024
1 parent a408848 commit 4aef046
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions genotype_api/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialise_database(db_uri: str) -> None:
"""Initialize the SQLAlchemy engine and session for genotype api."""
global SESSION, ENGINE

ENGINE = create_engine(db_uri, pool_pre_ping=True, pool_recycle=3600)
ENGINE = create_engine(db_uri, pool_pre_ping=True)
session_factory = sessionmaker(ENGINE)
SESSION = scoped_session(session_factory)

Expand Down Expand Up @@ -61,6 +61,10 @@ def get_tables() -> list[str]:
return inspector.get_table_names()


def close_session():
def close_session() -> None:
"""Close the global database session of the genotype api."""
SESSION.remove()
if SESSION:
session = SESSION()
if session.is_active:
session.rollback()
SESSION.remove()

0 comments on commit 4aef046

Please sign in to comment.