on_version_apply is typed as a positional callable, but alembic calls it with keyword arguments
Chưa có ai nhận issue này.
- #1886 của @anish-yen — đã đóng, không merge
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
Hướng nghiên cứu
Đọc các định nghĩa OnVersionApplyFn trong alembic/runtime/environment.py và alembic/context.pyi, sau đó so sánh chúng với lời gọi bằng đối số từ khóa trong alembic/runtime/migration.py. Cập nhật kiểu có thể gọi để khớp với các đối số từ khóa được tài liệu hóa và kiểm tra độ bao phủ kiểm tra kiểu liên quan. Công việc hoàn tất khi các trình kiểm tra kiểu chấp nhận callback được viết theo tài liệu và từ chối callback chỉ nhận đối số vị trí.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
EnvironmentContext.configure(on_version_apply=...) documents that "Each callable accepts no positional arguments and the following keyword arguments: ctx, step, heads, run_args", and MigrationContext.run_migrations() calls each callable that way (alembic/runtime/migration.py):
callback(
ctx=self,
step=step.info,
heads=set(head_maintainer.heads),
run_args=kw,
)
But the parameter is typed as a callable of four positional arguments, in alembic/runtime/environment.py and in alembic/context.pyi:
OnVersionApplyFn = Callable[
[MigrationContext, "MigrationInfo", Collection[Any], Mapping[str, Any]],
None,
]
So a type checker rejects a callback written as documented, and accepts one that fails at runtime.
Expected behavior
The type of on_version_apply describes the keyword arguments, for example:
class OnVersionApplyFn(Protocol):
def __call__(
self,
*,
ctx: MigrationContext,
step: MigrationInfo,
heads: Collection[Any],
run_args: Mapping[str, Any],
) -> None: ...
To Reproduce
from typing import Any
from alembic import context
from alembic.runtime.migration import MigrationContext, MigrationInfo
def as_documented(
*,
ctx: MigrationContext,
step: MigrationInfo,
heads: set[str],
run_args: dict[str, Any],
) -> None:
"""Takes the arguments by keyword, as documented."""
context.configure(on_version_apply=as_documented) # rejected by type checkers
def as_typed(
context_: MigrationContext, step: MigrationInfo, heads: Any, args: Any
) -> None:
"""Takes them by place, as typed."""
context.configure(on_version_apply=as_typed) # accepted; run_migrations() then fails
Error
pyright 1.1.407:
error: Argument of type "(*, ctx: MigrationContext, step: MigrationInfo, heads: set[str], run_args: dict[str, Any]) -> None" cannot be assigned to parameter "on_version_apply" of type "((MigrationContext, MigrationInfo, Collection[Any], Mapping[str, Any]) -> None) | None" in function "configure" (reportArgumentType)
pyrefly 1.3.2:
ERROR Argument `(*, ctx: MigrationContext, step: MigrationInfo, heads: set[str], run_args: dict[str, Any]) -> None` is not assignable to parameter `on_version_apply` with type `((MigrationContext, MigrationInfo, Collection[Any], Mapping[str, Any]) -> None) | None` in function `alembic.context.configure` [bad-argument-type]
at runtime, with as_typed:
TypeError: as_typed() got an unexpected keyword argument 'ctx'
Versions.
- OS: Linux, macOS
- Python: 3.14
- Alembic: 1.20.0
- SQLAlchemy: 2.0.54
- Database: PostgreSQL 17
- DBAPI: asyncpg
Additional context
Our workaround takes the arguments both ways: def on_apply(ctx, step, heads, run_args) -> None, the parameters named as alembic passes them.
Have a nice day!
- Ngôn ngữ chính
- Python
- Star
- 4.5k
- Fork
- 391
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của sqlalchemy/alembic
-
Revision message is rendered unescaped into the migration docstring; triple quotes and backslashes break the generated scriptCó thể làm lại được @ApparentlyTejas đã nhận 21 ngày trước và không có pull request nào đang mở. Đang mởbug command interface
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
sqlalchemy/alembic#1879 · 3 bình luận ·
-
bug pep 484
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
sqlalchemy/alembic#1341 · 2 bình luận ·
-
autogenerate - detection bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
sqlalchemy/alembic#1121 · 3 bình luận ·
-
Identity and Computed comparison skipped when compare_server_default is not set, as of 1.18.0Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởautogenerate - defaults bug regression
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 50/100
sqlalchemy/alembic#1877 · 1 bình luận ·
-
Entry point for DefaultImpl subclasses? (or, just use plugins?)Có thể đã có người làm @dwreeves đã nhận 40 ngày trước. Đang mởcode review in progress migration environment use case
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
sqlalchemy/alembic#1874 · 1 bình luận ·
Tất cả issue của sqlalchemy/alembic
Issue tương tự
-
SslLibrary crashes with unhandled OSError: port/proto not found on non-standard SSL portsCó thể đã có người làm @himanchalkaushale đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
OWASP/Nettacker#1884 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
A-connection-core C-enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
aws-samples/sample-per-model-bedrock#869 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Spec: say that included_antigen_sources gates LENS labels; do not merge it into antigen kindsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
fzn0x/watchtower#17 ·