Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cardinal_pythonlib/sqlalchemy/alembic_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ def get_current_revision(
version_table: table name for Alembic versions
"""
engine = create_engine(database_url, future=True)
conn = engine.connect()
opts = {"version_table": version_table}
mig_context = MigrationContext.configure(conn, opts=opts)
return mig_context.get_current_revision()
with engine.connect() as conn:
opts = {"version_table": version_table}
mig_context = MigrationContext.configure(conn, opts=opts)
return mig_context.get_current_revision()


def get_current_and_head_revision(
Expand Down
12 changes: 7 additions & 5 deletions cardinal_pythonlib/sqlalchemy/tests/schema_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,14 @@ def _attach_view(
of "selectable") is created after the table is created, and dropped before
the table is dropped, via listeners.
"""
t = table(tablename)

# noinspection PyProtectedMember
t._columns._populate_separate_keys(
col._make_proxy(t) for col in selectable.selected_columns
t = table(
tablename,
*(
Column(c.name, c.type, primary_key=c.primary_key)
for c in selectable.selected_columns
),
)
t.primary_key.update(c for c in t.c if c.primary_key)

event.listen(
metadata,
Expand Down
7 changes: 7 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -852,3 +852,10 @@ Quick links:
- Bugfix to ``cardinal_pythonlib.sqlalchemy.sqlserver`` functions as they
were executing unconditionally, regardless of SQLAlchemy dialect (they should
have been conditional to SQL Server).

**2.0.2**

- Bugfix to
:func:`cardinal_pythonlib.sqlalchemy.alembic_func.get_current_revision` where
since SQLAlchemy 2.0, the database connection was persisting, resulting in a
metadata lock.