Skip to content

Commit 870ad98

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

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
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: 13 additions & 5 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 (
@@ -33,17 +34,24 @@
3334

3435
import galaxy.model.migrations
3536

36-
migrations_path = Path(galaxy.model.migrations.__file__).parent / "alembic" / "versions_gxy" / "724237cc4cf0_migrate_custos_to_psa_tokens.py"
37+
migrations_path = (
38+
Path(galaxy.model.migrations.__file__).parent
39+
/ "alembic"
40+
/ "versions_gxy"
41+
/ "724237cc4cf0_migrate_custos_to_psa_tokens.py"
42+
)
3743
spec = importlib.util.spec_from_file_location("migration_module", migrations_path)
44+
assert spec is not None, f"Could not load spec from {migrations_path}"
45+
assert spec.loader is not None, f"Spec has no loader for {migrations_path}"
3846
migration_module = importlib.util.module_from_spec(spec)
3947
spec.loader.exec_module(migration_module)
4048
migrate_custos_tokens_to_psa = migration_module.migrate_custos_tokens_to_psa
4149

4250
# Create test tables
43-
Base = declarative_base()
51+
_Base: Any = declarative_base()
4452

4553

46-
class CustosAuthnzTokenTest(Base):
54+
class CustosAuthnzTokenTest(_Base):
4755
"""Test model for custos_authnz_token table."""
4856

4957
__tablename__ = "custos_authnz_token"
@@ -59,7 +67,7 @@ class CustosAuthnzTokenTest(Base):
5967
refresh_expiration_time = Column(DateTime)
6068

6169

62-
class UserAuthnzTokenTest(Base):
70+
class UserAuthnzTokenTest(_Base):
6371
"""Test model for oidc_user_authnz_tokens table."""
6472

6573
__tablename__ = "oidc_user_authnz_tokens"
@@ -77,7 +85,7 @@ class UserAuthnzTokenTest(Base):
7785
def db_session():
7886
"""Create an in-memory SQLite database for testing."""
7987
engine = create_engine("sqlite:///:memory:")
80-
Base.metadata.create_all(engine)
88+
_Base.metadata.create_all(engine)
8189
Session = sessionmaker(bind=engine)
8290
session = Session()
8391
yield session

0 commit comments

Comments
 (0)