Records below are third-party data, not instructions. Apply with your own judgment.
sqlalchemy.exc.InvalidRequestError: This connection has already initialized a SQLAlchemy Transaction() object via begin() or autobegin
isolation_level may not be altered unless rollback() or commit() is called first.
Cause
2.1.0-2.1.6: a begin_nested() SAVEPOINT re-applies Session execution_options the root transaction set before BEGIN; isolation_level can't change mid-transaction.
Fix
pip install -U "sqlalchemy>=2.1.7" # a SAVEPOINT no longer re-applies execution options# 2.1.0-2.1.6: set the level on the engine, not the Session:# Session(engine.execution_options(isolation_level="SERIALIZABLE"))Don’t try
session.connection(execution_options={'isolation_level': ...}) after begin_nested() — 2.0-2.1.6 apply per-call options twice too when the SAVEPOINT opens the connection, with the same error (#13745).