Skip to content

Annotate RDB model columns with Mapped to fix mypy errors with SQLAlchemy 2.1 - #6877

Merged
y0z merged 1 commit into
optuna:masterfrom
not522:sqlalchemy-2.1
Sep 30, 2026
Merged

y0z merged 1 commit into
optuna:masterfrom
not522:sqlalchemy-2.1

Conversation

@not522

@not522 not522 commented Sep 30, 2026

Copy link
Copy Markdown
Member

Motivation

The SQLAlchemy 2.1 release causes mypy to fail.

Description of the changes

  • Annotation for RDB model columns with Mapped. This ensures that when referenced from a class, SQL expressions are used, and when referenced from an instance, the actual value type is used.
  • Adding nullable=True. This is necessary to make nullable types explicit when they can't be inferred from the type.
  • Using the asc/desc methods to infer the correct types.
  • Using scalar_one instead of scalar in heartbeat because it is not optional.

Checklist

  • I used an LLM while working on this PR.

@not522 not522 assigned c-bata and y0z Sep 30, 2026
@not522 not522 added the CI Continuous integration. label Sep 30, 2026

@c-bata c-bata left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@c-bata c-bata added this to the v5.1.0 milestone Sep 30, 2026
@c-bata c-bata removed their assignment Sep 30, 2026

@y0z y0z left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@y0z
y0z merged commit 364e369 into optuna:master Sep 30, 2026
14 checks passed
@y0z y0z removed their assignment Sep 30, 2026
@not522
not522 deleted the sqlalchemy-2.1 branch September 30, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous integration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants