SQLAlchemy 2.1.0 breaks deployment scheduling on fresh installs
Bug summary
SQLAlchemy 2.1.0 was released today (2026-09-24), and sqlalchemy[asyncio]>=2.0,<3.0.0 lets a fresh install pick it up. On Python 3.11+, pip install prefect now gives Prefect 3.8.6 with SQLAlchemy 2.1.0. With that combination the server can no longer schedule runs for a deployment:
sqlalchemy.exc.InvalidRequestError: Can't evaluate bulk DML statement; please supply a bulk_dml decorated functionIt fails in _insert_scheduled_flow_runs (src/prefect/server/models/deployments.py), which the scheduler service and POST /deployments/{id}/schedule both use. CI doesn't catch this because it installs from uv.lock, which still pins 2.0.x.
Repro, in a fresh environment:
import asyncio, datetime, sqlalchemy, prefect
from prefect import flow
from prefect.client.orchestration import get_client
from prefect.client.schemas.actions import DeploymentScheduleCreate
from prefect.client.schemas.schedules import IntervalSchedule
@flow
def hello(): ...
async def main():
print("prefect", prefect.__version__, "sqlalchemy", sqlalchemy.__version__)
async with get_client() as client:
flow_id = await client.create_flow_from_name("hello")
deployment_id = await client.create_deployment(
flow_id=flow_id,
name="every-minute",
schedules=[
DeploymentScheduleCreate(
schedule=IntervalSchedule(interval=datetime.timedelta(minutes=1)),
active=True,
)
],
)
response = await client._client.post(
f"/deployments/{deployment_id}/schedule", json={"max_runs": 5}
)
print("POST /deployments/{id}/schedule ->", response.status_code)
print("scheduled flow runs:", len(await client.read_flow_runs()))
asyncio.run(main())$ uv venv -p 3.12 && uv pip install prefect && python repro.py
prefect 3.8.6 sqlalchemy 2.1.0
ERROR | uvicorn.error - Exception in ASGI application
sqlalchemy.exc.InvalidRequestError: Can't evaluate bulk DML statement; please supply a bulk_dml decorated function
$ uv pip install 'sqlalchemy==2.0.49' && python repro.py
prefect 3.8.6 sqlalchemy 2.0.49
POST /deployments/{id}/schedule -> 200
scheduled flow runs: 5Running the server tests against 2.1.0 (uv run --with 'sqlalchemy[asyncio]==2.1.0' pytest tests/server tests/events/server, SQLite) shows more than this one call site:
- Every database test errors under
filterwarnings = error:SADeprecationWarning: Type object <class 'prefect.server.utilities.database.UUID'> does not refer to an OperatorClass in its operator_classes attribute. This attribute will be required in a future release. - With that warning ignored, 50 tests still fail. These include deployment scheduling (
TestScheduledRuns,TestScheduleDeployment,test_scheduler.py),read_flow_runswith selected columns (MissingGreenleton a lazy load of an unloaded column), andtest_flow_run_graph_v2.py.
Also: the 2.1.0 sdist has a duplicate extra (mssql-pymssql) in its pyproject.toml that uv refuses to parse. Builds that picked up the sdist while the wheels were still uploading (the Docker and Benchmark jobs on #23198) failed on it.
Version info
prefect 3.8.6 (PyPI) and main @ 148e99781, Python 3.12/3.13, SQLAlchemy 2.1.0, SQLiteAdditional context
I'll open a PR that caps SQLAlchemy below 2.1 so new installs are safe. Supporting 2.1 needs changes across the server (bulk inserts, UUID type operator classes, column loading), which seems better left to a maintainer-owned change.
Source: PrefectHQ/prefect