From be7e5b13a754d94e5010ffbf0d6c71e427766521 Mon Sep 17 00:00:00 2001 From: Azhar Date: Sun, 5 Apr 2026 10:48:13 +0530 Subject: [PATCH] Fix migrations release lock issue --- edda/storage/migrations.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/edda/storage/migrations.py b/edda/storage/migrations.py index 478c72e..83988b1 100644 --- a/edda/storage/migrations.py +++ b/edda/storage/migrations.py @@ -182,9 +182,9 @@ async def migration_lock(engine: AsyncEngine, db_type: str) -> AsyncIterator[boo yield True return - acquired = False - try: - async with engine.connect() as conn: + async with engine.connect() as conn: + acquired = False + try: if db_type == "postgresql": # Try to acquire advisory lock (non-blocking) result = await conn.execute( @@ -202,18 +202,17 @@ async def migration_lock(engine: AsyncEngine, db_type: str) -> AsyncIterator[boo logger.debug("Could not acquire migration lock, another worker is migrating") yield False - finally: - if acquired: - try: - async with engine.connect() as conn: + finally: + if acquired: + try: if db_type == "postgresql": await conn.execute(text(f"SELECT pg_advisory_unlock({MIGRATION_LOCK_KEY})")) await conn.commit() elif db_type == "mysql": await conn.execute(text("SELECT RELEASE_LOCK('edda_migration')")) await conn.commit() - except Exception as e: - logger.warning(f"Failed to release migration lock: {e}") + except Exception as e: + logger.warning(f"Failed to release migration lock: {e}") def extract_version_from_filename(filename: str) -> str: