Describe the bug
Type definition of BatchOperations.alter_column uses wrong types for parameter existing_server_default, not specifying TextClause as part of type union. Consequently, Pylance happens to be triggered when sa.text(...) is used as an argument, despite the fact that at runtime this type is accepted, and in docs this is a recommended technique.
Expected behavior
No type errors should occur in example code below. This can be achieved only by changes in type hints.
To Reproduce
Please try to provide a Minimal, Complete, and Verifiable example, with the migration script and/or the SQLAlchemy tables or models involved.
See also Reporting Bugs on the website.
def upgrade() -> None:
"""Upgrade schema."""
with op.batch_alter_table("machine_tokens", schema=None) as batch_op:
batch_op.alter_column(
"created_at",
existing_type=sa.DATETIME(),
nullable=False,
existing_server_default=sa.text("(CURRENT_TIMESTAMP)"), # <-- here Pylance shows the error
)
Error
Note that this is strictly type checking error. It won't occur at runtime. Thus, there's no strict need to run that code, other than to verify that the type is actually accepted at runtime.
Argument of type "TextClause" cannot be assigned to parameter "existing_server_default" of type "str | bool | Identity | Computed | None" in function "alter_column"
Type "TextClause" is not assignable to type "str | bool | Identity | Computed | None"
"TextClause" is not assignable to "str"
"TextClause" is not assignable to "bool"
"TextClause" is not assignable to "Identity"
"TextClause" is not assignable to "Computed"
"TextClause" is not assignable to "None"
Versions.
- OS: Windows 11 Version 25h2
- Python: 3.14.0 (uv-managed)
- Alembic: 1.17.2
- SQLAlchemy: 2.0.45
- Database: SQLite (not related, though)
- DBAPI:
pysqlite
Have a nice day!
Describe the bug
Type definition of
BatchOperations.alter_columnuses wrong types for parameterexisting_server_default, not specifyingTextClauseas part of type union. Consequently, Pylance happens to be triggered whensa.text(...)is used as an argument, despite the fact that at runtime this type is accepted, and in docs this is a recommended technique.Expected behavior
No type errors should occur in example code below. This can be achieved only by changes in type hints.
To Reproduce
Please try to provide a Minimal, Complete, and Verifiable example, with the migration script and/or the SQLAlchemy tables or models involved.
See also Reporting Bugs on the website.
Error
Note that this is strictly type checking error. It won't occur at runtime. Thus, there's no strict need to run that code, other than to verify that the type is actually accepted at runtime.
Versions.
pysqliteHave a nice day!