Skip to content

Commit 4aef046

Browse files
committed
rollback before closing active session
1 parent a408848 commit 4aef046

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

genotype_api/database/database.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def initialise_database(db_uri: str) -> None:
1616
"""Initialize the SQLAlchemy engine and session for genotype api."""
1717
global SESSION, ENGINE
1818

19-
ENGINE = create_engine(db_uri, pool_pre_ping=True, pool_recycle=3600)
19+
ENGINE = create_engine(db_uri, pool_pre_ping=True)
2020
session_factory = sessionmaker(ENGINE)
2121
SESSION = scoped_session(session_factory)
2222

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

6363

64-
def close_session():
64+
def close_session() -> None:
6565
"""Close the global database session of the genotype api."""
66-
SESSION.remove()
66+
if SESSION:
67+
session = SESSION()
68+
if session.is_active:
69+
session.rollback()
70+
SESSION.remove()

0 commit comments

Comments
 (0)