Skip to content

Commit f7e3109

Browse files
Close connection when retrieving current alembic version
CamCOPS upgrade_db was hanging when upgrading the database due to this open connection causing a metadata lock.
1 parent c97edc5 commit f7e3109

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cardinal_pythonlib/sqlalchemy/alembic_func.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ def get_current_revision(
104104
version_table: table name for Alembic versions
105105
"""
106106
engine = create_engine(database_url, future=True)
107-
conn = engine.connect()
108-
opts = {"version_table": version_table}
109-
mig_context = MigrationContext.configure(conn, opts=opts)
110-
return mig_context.get_current_revision()
107+
with engine.connect() as conn:
108+
opts = {"version_table": version_table}
109+
mig_context = MigrationContext.configure(conn, opts=opts)
110+
return mig_context.get_current_revision()
111111

112112

113113
def get_current_and_head_revision(

0 commit comments

Comments
 (0)