SQLAlchemy 2.0.0, released on January 26, 2023, removes the Python database toolkit’s library-level automatic commits. Code that previously inserted a row and relied on SQLAlchemy to commit it now needs to handle that transaction explicitly. Applications that have not completed the 1.x migration should constrain their dependency requirements to the intended major release, the announcement warns. [S1][S7]

The release also removes Engine.execute(), the convenience method that executed a statement without the caller first obtaining a connection. Statement execution moves to Connection.execute(), or Session.execute() for the object-relational mapper. A simple rename is not enough: Connection.execute() no longer accepts a bare SQL string. The migration guide directs callers to wrap textual SQL with text(), or use exec_driver_sql() when passing SQL directly to the database driver. [S7]

An insert that executes still needs its transaction handled. The guide shows explicit transaction blocks using Engine.begin() or Connection.begin() as an approach compatible with both 1.x and 2.0. The newer connection also supports commit-as-you-go: execute the statements, then call Connection.commit(), or roll back instead. Its autobegin behavior starts a transaction when work first occurs without an explicit begin call; it does not commit that work. The old execution option autocommit=True is removed, so it cannot serve as a migration shortcut. [S7]

Driver-level autocommit is a separate case and remains available. SQLAlchemy supports it through the connection’s isolation_level execution option where the database driver provides that mode. With driver autocommit enabled, the guide says begin contexts and commit calls can remain in the application but are no-ops at the driver level. Check which layer supplies the existing behavior before changing a working connection configuration. [S7]

Teams can expose affected paths while still running 1.4. On SQLAlchemy 1.4, set SQLALCHEMY_WARN_20=1 and configure Python’s warning filter so it does not suppress deprecation warnings. The guide also describes turning warnings into exceptions to obtain a useful stack trace. After resolving the engine and connection warnings, create_engine(..., future=True) enables the 2.0-style engine behavior on 1.4, including the removal of implicit autocommit. The migration guide still calls for a final test against an actual 2.0 release because other API and behavior differences can remain. [S7]

For a write-heavy job, a useful acceptance test would finish the job, then check the expected records from a fresh connection. Exercise the rollback path separately. Those checks follow from the change in transaction responsibility: a successful execute call alone does not show that the job committed its changes. [S7]

Source documents

  1. SQLAlchemy 2.0.0 Released — January 26, 2023https://www.sqlalchemy.org/blog/2023/01/26/sqlalchemy-2.0.0-released/
  2. SQLAlchemy 2.0 Major Migration Guide — release 2.0.0 pinned sourcehttps://raw.githubusercontent.com/sqlalchemy/sqlalchemy/ad2a65ef7e3cd57912c6c0373c8b843b8a1730eb/doc/build/changelog/migration_20.rst