Skip to content

Conversation

@GeiserX
Copy link
Owner

@GeiserX GeiserX commented Feb 13, 2026

Summary

  • Fix PostgreSQL migrations silently rolling back due to advisory lock triggering SQLAlchemy's autobegin before context.configure(), causing Alembic to skip transaction management
  • Switch from session-level pg_advisory_lock() to transaction-scoped pg_advisory_xact_lock() inside the begin_transaction() block

Root Cause

The advisory lock in alembic/env.py was acquired before context.configure(). This triggered SQLAlchemy's autobegin, which made Alembic detect _in_external_transaction=True and return nullcontext() from begin_transaction() -- skipping all commit logic. DDL ran but was rolled back on connection close.

Test plan

  • Verify PostgreSQL migration 006 applies correctly on a fresh database
  • Verify PostgreSQL migration is a no-op when already at version 006
  • Verify SQLite migrations still work (no advisory lock path)
  • Verify concurrent container starts don't deadlock (advisory lock still active)

Fixes #70

The advisory lock acquired before context.configure() triggered
SQLAlchemy's autobegin, causing Alembic to detect an "external
transaction" and skip its own commit. Switched to pg_advisory_xact_lock()
inside begin_transaction() so DDL changes are properly committed.

Fixes #70
@GeiserX GeiserX merged commit 01f8d89 into master Feb 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SQL Error in Viewer

1 participant