lablup / lablup/backend.ai

Replace Any-typed generate_base() with SQLAlchemy 2.0 DeclarativeBase

Open
#13,631 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
17h 7m
Merged PRs (30d)
358

Description

manager/models/base.py defines the ORM base as `Base: Any = mapper_registry.generate_base()` with a TODO referencing dropbox/sqlalchemy-stubs#422. That stubs project was abandoned when SQLAlchemy 2.0 shipped native inline typing, so the TODO can never be resolved as written. The repo already pins SQLAlchemy ~=2.0.45 and the model classes are already migrated to the Mapped[] / mapped_column() style (no class-level sa.Column left outside alembic snapshots), so the typed DeclarativeBase can be adopted directly.

Scope:

- Replace the Any-typed base with a DeclarativeBase subclass that reuses the existing mapper_registry/metadata (naming convention preserved), in manager/models/base.py and account_manager/models/base.py which has the same pattern.
- Remove the ~58 `# type: ignore[misc]` comments on Row classes that only existed because subclassing an Any-typed Base is a mypy error.
- Fix any real type errors that surface now that model classes are type-checked for the first time; verify with the same pants check scope as CI.

JIRA Issue: BA-7293

Contributor guide

Open the contributing guide

Research direction

Start by comparing manager/models/base.py and account_manager/models/base.py, then inspect the Row classes with the existing type: ignore[misc] comments. Run the same pants check scope used by CI to identify real typing errors after the base change. Done means both bases reuse their existing mapper registry and metadata, the obsolete ignores are removed, and the check passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlalchemy
Domain
backend, database
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.