Skip to content

Commit fcf9637

Browse files
committed
Fix mypy type errors in migration scripts
1 parent d162f79 commit fcf9637

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/galaxy/model/migrations/alembic/versions_gxy/724237cc4cf0_migrate_custos_to_psa_tokens.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ def get_custos_table(connection):
4343
4444
This function can be reused by both migration scripts and tests.
4545
"""
46+
from sqlalchemy import MetaData
47+
48+
metadata = MetaData()
4649
return Table(
4750
CUSTOS_TABLE,
48-
(
49-
op.get_bind().dialect.get_columns(op.get_bind(), CUSTOS_TABLE)
50-
if hasattr(op.get_bind().dialect, "get_columns")
51-
else []
52-
),
51+
metadata,
5352
Column("id", Integer, primary_key=True),
5453
Column("user_id", Integer),
5554
Column("external_user_id", String(255)),
@@ -70,13 +69,12 @@ def get_psa_table(connection):
7069
7170
This function can be reused by both migration scripts and tests.
7271
"""
72+
from sqlalchemy import MetaData
73+
74+
metadata = MetaData()
7375
return Table(
7476
PSA_TABLE,
75-
(
76-
op.get_bind().dialect.get_columns(op.get_bind(), PSA_TABLE)
77-
if hasattr(op.get_bind().dialect, "get_columns")
78-
else []
79-
),
77+
metadata,
8078
Column("id", Integer, primary_key=True),
8179
Column("user_id", Integer, ForeignKey("galaxy_user.id")),
8280
Column("uid", VARCHAR(255)),

test/unit/data/model/test_migrate_custos_to_psa.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
timedelta,
1414
)
1515
from pathlib import Path
16+
from typing import Any
1617

1718
import pytest
1819
from sqlalchemy import (
@@ -35,15 +36,17 @@
3536

3637
migrations_path = Path(galaxy.model.migrations.__file__).parent / "alembic" / "versions_gxy" / "724237cc4cf0_migrate_custos_to_psa_tokens.py"
3738
spec = importlib.util.spec_from_file_location("migration_module", migrations_path)
39+
assert spec is not None, f"Could not load spec from {migrations_path}"
40+
assert spec.loader is not None, f"Spec has no loader for {migrations_path}"
3841
migration_module = importlib.util.module_from_spec(spec)
3942
spec.loader.exec_module(migration_module)
4043
migrate_custos_tokens_to_psa = migration_module.migrate_custos_tokens_to_psa
4144

4245
# Create test tables
43-
Base = declarative_base()
46+
_Base: Any = declarative_base()
4447

4548

46-
class CustosAuthnzTokenTest(Base):
49+
class CustosAuthnzTokenTest(_Base):
4750
"""Test model for custos_authnz_token table."""
4851

4952
__tablename__ = "custos_authnz_token"
@@ -59,7 +62,7 @@ class CustosAuthnzTokenTest(Base):
5962
refresh_expiration_time = Column(DateTime)
6063

6164

62-
class UserAuthnzTokenTest(Base):
65+
class UserAuthnzTokenTest(_Base):
6366
"""Test model for oidc_user_authnz_tokens table."""
6467

6568
__tablename__ = "oidc_user_authnz_tokens"
@@ -77,7 +80,7 @@ class UserAuthnzTokenTest(Base):
7780
def db_session():
7881
"""Create an in-memory SQLite database for testing."""
7982
engine = create_engine("sqlite:///:memory:")
80-
Base.metadata.create_all(engine)
83+
_Base.metadata.create_all(engine)
8184
Session = sessionmaker(bind=engine)
8285
session = Session()
8386
yield session

0 commit comments

Comments
 (0)