Bug: BatchOperations.create_index has incorrect signature #1850
Describe the bugThe signature (according to the docs and the API in the generated section of base.py) of BatchOperations.create_index is def create_index(self, index_name: str, columns: list[str], **kw: Any) -> NoneThe signature of Operations.create_index is def create_index(self, index_name: str | None, table_name: str, columns: Sequence[str | TextClause | ColumnElement[Any]], *, schema: str | None = None, unique: bool = False, if_not_exists: bool | None = None, **kw: Any) -> NoneHaving taken a very brief look at where these functions come from I believe the signatures must be the same (aside from the missing table_name) as they are backed by the same implementation, but my (possibly — and even somewhat likely — incorrect) beliefs aside, with op.batch_alter_table('table_name', schema=None) as batch_op:
batch_op.create_index(batch_op.f('idx_name'), [sa.literal_column('"col1_name" DESC'), sa.literal_column('"col2_name" DESC')], unique=False)which is not valid for BatchOperations' version, which declares
Expected behaviorThe signature of To ReproduceRun from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'b23c5a130bc8'
down_revision: Union[str, Sequence[str], None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade(engine_name: str) -> None:
"""Upgrade schema."""
with op.batch_alter_table('prm_contacts', schema=None) as batch_op:
batch_op.create_index(batch_op.f('idx_test_idx_delete_me'), [sa.literal_column('"NAME" DESC'), sa.literal_column('"PHONE" DESC')], unique=False)
def downgrade(engine_name: str) -> None:
"""Downgrade schema."""
with op.batch_alter_table('prm_contacts', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('idx_test_idx_delete_me'))ErrorIn this example using Versions
Additional contextI am writing this bug report as a discussion since the reporting bugs guidance asks to do so instead of opening an issue, but none of the categories of discussions look right... I chose the one that seems least inappropriate and marked the actual nature in the title. Please let me know if that was not the right choice. Footnotes
|
Replies: 1 comment
|
Hi. it seems so. Thanks for reporting. The signature to update should be this one alembic/alembic/operations/ops.py Line 1007 in dac4723 I'll create an issue and apply the correct label to open PRs |
Hi.
it seems so. Thanks for reporting.
The signature to update should be this one
alembic/alembic/operations/ops.py
Line 1007 in dac4723
I'll create an issue and apply the correct label to open PRs