on_version_apply is typed as a positional callable, but alembic calls it with keyword arguments
Nessuno ha ancora preso questa issue.
- #1886 di @anish-yen — chiusa senza merge
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
Direzione di ricerca
Leggi le definizioni di OnVersionApplyFn in alembic/runtime/environment.py e alembic/context.pyi, quindi confrontale con la chiamata con argomenti denominati in alembic/runtime/migration.py. Aggiorna il tipo chiamabile in modo che corrisponda agli argomenti denominati documentati e verifica la copertura di tipizzazione correlata. Il lavoro è completato quando i type checker accettano un callback scritto come documentato e rifiutano un callback che accetta solo argomenti posizionali.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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!
- Lingua principale
- Python
- Stelle
- 4.5k
- Fork
- 391
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sqlalchemy/alembic
-
Revision message is rendered unescaped into the migration docstring; triple quotes and backslashes break the generated scriptForse di nuovo libera @ApparentlyTejas l’ha presa 21 giorni fa e non c’è nessuna pull request aperta. Apertabug command interface
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
sqlalchemy/alembic#1879 · 3 commenti ·
-
bug pep 484
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
sqlalchemy/alembic#1341 · 2 commenti ·
-
autogenerate - detection bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
sqlalchemy/alembic#1121 · 3 commenti ·
-
Identity and Computed comparison skipped when compare_server_default is not set, as of 1.18.0Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertaautogenerate - defaults bug regression
Difficoltà 3/5 1-2 giorni Idoneità per principianti 50/100
sqlalchemy/alembic#1877 · 1 commento ·
-
Entry point for DefaultImpl subclasses? (or, just use plugins?)Forse già presa @dwreeves l’ha presa 40 giorni fa. Apertacode review in progress migration environment use case
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
sqlalchemy/alembic#1874 · 1 commento ·
Tutte le issue di sqlalchemy/alembic
Issue simili
-
SslLibrary crashes with unhandled OSError: port/proto not found on non-standard SSL portsForse già presa @himanchalkaushale l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
OWASP/Nettacker#1884 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
A-connection-core C-enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
aws-samples/sample-per-model-bedrock#869 ·
I maintainer di solito rispondono entro 1 giorno
-
Spec: say that included_antigen_sources gates LENS labels; do not merge it into antigen kindsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
fzn0x/watchtower#17 ·