Describe the bug
Documentation for op.execute describes the sqltext argument thus:
Parameters: sqltext – Any legal SQLAlchemy expression, including:
But the sqltext argument is actually declared as sqltext: str | TextClause | Update — TextClause and Update are the only SQL expressions it is typed to accept, and any attempt to use any other expression type (e.g. an Insert or Delete) will cause mypy to not validate the call, and IDE typecheckers (e.g. VS Code's Pylance) to highlight an error.
Also, sqlalchemy.sql.expression.insert() is listed once as its own bullet point, and a second time in a separate bullet point, together with ...update() and ...delete().
Expected behavior
op.execute should be declared to accept all of the documented types of SQL expressions. Using expressions documented as acceptable should not produce mypy errors.
To Reproduce
# in migration script:
...
def upgrade() -> None:
table = op.create_table(...)
op.execute(table.insert().values(...))
...
Error
$ mypy alembic/versions/...version_filename....py
...version_filename....py:52: error: Argument 1 to "execute" has incompatible type "Insert"; expected "str | TextClause | Update" [arg-type]
Found 1 error in 1 file (checked 1 source file)
Versions.
- OS: macOS 13.4.1
- Python: 3.11.4
- Alembic: 1.11.1
- SQLAlchemy: 2.0.19
- Database: irrelevant
- DBAPI: irrelevant
Have a nice day!
Describe the bug
Documentation for
op.executedescribes thesqltextargument thus:But the
sqltextargument is actually declared assqltext: str | TextClause | Update—TextClauseandUpdateare the only SQL expressions it is typed to accept, and any attempt to use any other expression type (e.g. anInsertorDelete) will causemypyto not validate the call, and IDE typecheckers (e.g. VS Code's Pylance) to highlight an error.Also,
sqlalchemy.sql.expression.insert()is listed once as its own bullet point, and a second time in a separate bullet point, together with...update()and...delete().Expected behavior
op.executeshould be declared to accept all of the documented types of SQL expressions. Using expressions documented as acceptable should not producemypyerrors.To Reproduce
Error
Versions.
Have a nice day!